Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-10-18 07:51:52


Johan Nilsson wrote:
> Peter Dimov wrote:
>> Johan Nilsson wrote:
>>
>>> It's possible to handle spurious wakeups with relative times as
>>> well, perhaps just not perfectly (depending on underlying platform
>>> support). If
>>> the only way to perform a timed wait on a condition variable is by
>>> an absolute time, I believe the most common usage will be something
>>> like this (pseudocode):
>>>
>>> ---
>>> time now = microsec_clock::local_time();
>>> time timeout = now + milliseconds(250);
>>> if (!cv.timed_wait(lk, timeout, my_pred()))
>>> {
>>> throw "Timed out!";
>>> }
>>
>> You are missing a loop.
>
> I think you're missing the predicate "my_pred()".

You are right, I was. Relative timeouts do indeed make sense for the
predicate version, if (1) you are willing to accept the inconsistency and
(2) you are only concerned with use cases like the above where the timeout
is not a deadline but a safety net.

An additional relative timeout overload in the cases where it's appropriate
could work, but the current templatization does not allow it unless concepts
come into play.


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