Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-10-08 08:48:33

Roland Schwarz wrote:
> Peter Dimov wrote:
>> Does this mean that timed_wait( lock, xt, pred ) has a bug? Instead
>> of
>> while (!pred()) { if (!timed_wait(lock, xt)) return false; } return
>> true;
>> it needs to be
>> while (!pred()) { if (!timed_wait(lock, xt)) return pred(); } return
>> true;
>> otherwise a 'false' return can consume a signal meant for someone
>> else without notifying the caller to handle the pred() == true case?
> The documentation states:
> Returns: false if xt is reached, otherwise true.
> So if it returned pred instead you wouldn't get the correct result.
> I.e. when using the timed_wait you are deliberately missing the
> signal when it arrives out of time. It simply does not matter if
> the signal arrived after timeout.

It does matter. Consider the case where two threads are awaiting an element
to be pushed into a queue, one uses timed_wait, the other uses wait. The
"element pushed" signal arrives concurrently with the timeout, the
timed_wait thread is awakened, sees timeout, returns false to its caller,
who consequently doesn't pop the element. The other thread waits forever,
and the element remains in the queue.

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