From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-09-01 13:50:40
On Mon, Sep 1, 2008 at 7:44 PM, Stjepan Rajko <stipe_at_[hidden]> wrote:
> On Mon, Sep 1, 2008 at 9:35 AM, Giovanni Piero Deretta
> <gpderetta_at_[hidden]> wrote:
>> On Mon, Sep 1, 2008 at 7:19 AM, Jaakko Järvi <jarvi_at_[hidden]> wrote:
>>> The review of Stjepan Rajko's Dataflow library starts today, September 1st,
>>> and will run until September 10th.
>> Hi, while skimming through the Dataflow documentation, I noticed an
>> error in the distributed example (http://tinyurl.com/5qcjxx):
> Thanks for raising this issue - threading is definitely not my forte,
> and it's quite possible that I'm doing something weird. I see,
> looking at the docs:
> template <typename ScopedLock>
> void wait(ScopedLock& lock);
> Danger: This version should always be used within a loop checking that
> the state logically associated with the condition has become true.
> Without the loop, race conditions can ensue due to possible "spurious
> wake ups".
> I wasn't aware of the "spurious wake ups" issue. I will fix the code
> as you recommended.
Spurious wakeups are rare in practice. OTOH, what is more likely to
happen is that the main thread could miss the wake-up if the worker
thread managed to signal the condition variable before the main thread
got to wait for it (remember that condition variables are stateless).