
Alexander Bernauer <alex@copton.net> writes:
Why is it, that the wait and timed_wait functions of the condition_variable class do not encapsulate the problem of spurious wakeups?
Avoiding spurious wake-ups complicates the design considerably, and was the cause of a bug in the win32 implementation of boost::condition_variable.
I wonder whether there are good reasons. I have seen libraries which do so. Do they miss a corner case?
There are various complications with condition variables. It is likely that an implementation that avoids spurious wake-ups either imposes additional serialization on calls to notify_xxx/wait (e.g. through the use of an additional mutex in the cond var) or misses a corner case. When you get a spurious wake, just check the associated condition, and wait again if it is not met. The predicated overload of wait() will do this for you. Anthony -- Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976