Boost logo

Boost :

Subject: Re: [boost] [threads] API Design Question
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2009-02-04 15:57:10

Alexander Bernauer <alex_at_[hidden]> 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

> 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.


Author of C++ Concurrency in Action |
just::thread C++0x thread library   |
Just Software Solutions Ltd         |
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

Boost list run by bdawes at, gregod at, cpdaniel at, john at