
PJ Durai wrote:
On 4/18/07, Ken
wrote: On Apr 13, 2007, PJ Durai wrote:
I have two threads waiting on a condition. When I call condition::notify_all() from the main thread, I expected both threads to fall through and proceed simultaneously.
But that is not what I am witnessing. They behave like I had called condition::notify_one() twice.
One thread continues, does its thing (in this case a simple Sleep and a printf) comes back to wait. Only after that point the second thread continued from the condition.
Is this expected ? What am I missing ?
This is expected. condition::wait reacquires the mutex after it returns. You then call Sleep(4000) with the mutex locked; the other threads can't continue because they are waiting for the mutex. Try unlocking lk before Sleep'ing.