Boost logo

Boost :

Subject: Re: [boost] [threads] API Design Question
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2009-02-04 12:26:30


Alexander Bernauer wrote:
> Why is it, that the wait and timed_wait functions of the
> condition_variable class do not encapsulate the problem of spurious
> wakeups?

Hi Alexander,

Practically all of my use of conditions looks something like this:

   lock l(mut);
   while (temperature < threshold) {
     cond.wait(l);
   }

Or the equivalent using the predicate version of wait. This sort of
usage tolerates spurious wakeups. Furthermore, my "temperature <
threshold" test is as cheap as a spuriousness test would be, so adding
a spuriousness test would not even make it faster even if spurious
wakeups were frequent.

I'm curious to know what sort of use you are making of condition
variables where hiding spurious wakeups is important. Are trying to
announce events via the condition without any additional state?

Regards, Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk