
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 ?
Its possible. notify_all() will make the threads ready to run, its up to the OS as to when they actually run. So if the Sleep is short enough, what you observe could happen. On a win32 platform, though, I would expect the second thread to wake when the first encounters the Sleep().
I can post the code if anyone wants to take a look.
Yes, this would help. Ken Krovchuck