[Kde-pim] Threaded ldap search class
Szombathelyi György
gyurco at freemail.hu
Tue Apr 10 23:02:41 BST 2007
Hi,
>It seems OK so far. I'm making some more changes to the separate thread
>version at the moment. I've changed the API a little so that it accepts an
>LdapServer object rather than an LdapConnection. This way the search object
>can create its own connection in the new thread and not have to worry about
>protecting access to it from the calling thread. It seems safer this way as
>there doesn't seem to be much info in the ldap man pages about
>multithreading.
Oh, thread safety. This is harder than you (and me) thinked. I found out that
the OpenLDAP client libs are absolutely _not_ thread safe, even if you link
to _r versions, so the above use-case can also fail, if an app starts more
than one search parallel. E.g it could call non-reentrant glibc functions,
simply a gethostbyname() can broke the app (and if you create connections in
multiple threads that will happen!).
Here's a thread which is not promising:
http://www.mail-archive.com/openldap-software%40openldap.org/msg08198.html
The possible solutions I can imagine:
- Force the users of the class to use only one search thread. But It can break
too, when you mix LdapThreadSearch and other LdapOperations methods.
- Try to put only ldap_result (your waitForResult() func in LdapOperation) to
the thread, and pray that this lonely function is reentrant.
- Give up this great thing, and use the event loop again, but be smarter:
don't block till a message arrives, but poll (call waitForResult with 0
msec - but that can be slow, and CPU consuming), or block for a small amount
of time (e.g. 10 msecs).
>Once I'm done with those changes, I'll merge it into LdapSearch and post it
>here for comments and testing.
Now do you feel you'll want to to this? :)
Of course my reasoning could be totally wrong, I'm hoping this, too!
Eventually, If you finish the threaded version, I'd like to torture it with
100 LdapSearch objects :))
Bye,
György
_______________________________________________
kde-pim mailing list
kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/
More information about the kde-pim
mailing list