This solution will deadlock if all worker threads are stuck in a write
wait. Since the semaphore completely blocks the listener thread, there
will be no way to wake up the waiting writers and free up more
threads. Also, blocking the listener thread like this prevents the
idletimeout checker from working. I.e., you have managed to disable
two key mechanisms for returning server resources to the pool,
precisely when they are needed the most.
The listener thread must never block, period.
It would be better to simply have ldap_pvt_thread_pool_submit return a
result code (e.g. LDAP_BUSY if the submitted op will be queued because
there are no available workers, LDAP_SUCCESS otherwise) that is passed
back to the listener thread. When the listener thread gets this result
it should drop all read descriptors from the event set, but keep
monitoring the wake_sds and the write events.
Alternatively we should stop monitoring write events and just let the
writers unblock themselves. Is there a particular reason why we
monitor write events? I don't see any benefit. Eliminating one set of
event sources would reduce our kernel load by half.