> Why do mutex locking/unlocking around the cond_wait()?  In the original
> implementation, the worker thread just locked the mutex once at startup
> and then let the cond_wait() unlock and re-lock it for each connection.
> With this new code, we're now doing twice as many lock/unlock operations
> per request.

We can't just rely on waking up from cond_wait() to mean that the
condition was reached, we have to check some state. Otherwise we aren't
protecting from spurrious wakeups. We test for that condition by checking
what state the worker is in when it wakes up, and to set that state we
have to hold the mutex.

-aaron

Reply via email to