On Thu, 24 Sep 2009, Howard Chu wrote:
It seems the dichotomy between libldap and libldap_r is a relic from the bad old days of dcethreads / cmathreads when linking a threaded library into an otherwise non-threaded program would cause all sorts of strange and wonderful failures.
Hmm, my impression from reading the source was that it was more about use models, where libldap is appropriate when any given LDAP handle would not be accessed concurrently by multiple threads and libldap_r is appropriate when a given LDAP handle may be serviced/used concurrently by multiple threads.
Indeed, my impression from reading the ldap_r bits was that processing of replies wasn't ideal when threads were asking for specific replies, as asking for a given reply blocked *all* other ldap_result() calls on that handle until that specific reply was received.
(To hopefully make clear: thread1 thread2 ldap_result(h, msg_A) ldap_result(h, msg_B) receive msg_B <still blocked...> receive msg_A return from ldap_result return from ldap_result )
For an application design where that would be a problem, it's better off with independent handles or its own demultiplexor...at which point all those locks inside the LDAP handle are just overhead. At Sendmail, several of our commercial programs use a library to manage reconnections, resubmitting queries after failover between servers, etc. They all just link against libldap** and not libldap_r, despite having multiple threads concurrently in the LDAP code, because those extra locks would be wasted given the design.
** compiled with whatever it takes to get a thread-safe errno, etc
..
libldap_r is still missing some thread-specific features though - we should wrap all library initialization in a pthread_once() call, and we should be using thread-specific data for the LDAP* errno value.
Without knowing what usage models this is supposed to address or provide, I don't see the benefit.
Philip Guenther