Boost logo

Boost :

From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2007-10-18 03:36:36


Jeff Garland wrote:
> Johan Nilsson wrote:
>
>>> * timed_lock functions now take boost::system_time (a typedef to
>>> boost::posix_time::ptime from the date_time library) rather than
>>> xtime
>>
>> If you are going to make a breaking change - why not add an
>> time_duration overload, please? Even if almost everything is better
>> than the current xtime interface, I've so far never had a
>> requirement to use an absolute time for waiting or sleeping.
>> Absolute times is most often just a real pain to use, and in its
>> current implementation also misleading.
>>
>> (I've read the rationale in Programming with POSIX Threads, but I'm
>> not convinced.)
>
> n2320 calls for interfaces with time_duration on all timed_lock
> functions.

What about sleep?

> Only the condition variable adds an absolute time (eg:
> system_time) which is to handle spurious wakeups.

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!";
}
---
Now, my intention is clearly to wait for a maximum, _relative_, time before 
something happens. I'm not interested in whether it occurs before a specific 
absolute time or not. Besides that, the above code is subject to race 
conditions (as the system time can be set at any time).
Also, if this timed wait implementation is (as in Boost <= 1.34.1) 
internally converting to relatively timed waits, the interface is lying to 
me. If I use an absolute time as the time parameter, I'd expect the method 
not to return until the system time has actually reached that time - no 
matter if someone unexpectedly set the time forward one hour just before I 
call timed_wait above.
Just my 0.02EUR.
/ Johan

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