Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2007-11-27 10:46:22


Thorsten Froehlich <froetho_at_[hidden]> writes:

> Anthony Williams wrote:
>>> Making this change, the race condition goes away on one more platform using
>>> in the boost interface. It should also be considered that relative timeouts
>>> in the boost interface certainly eliminate a problem on a platform with a
>>> large market share relevant to many boost developers for better or worse ;-)
>>
>> How does the race condition go away by making everyone use relative timeouts?
>
> You no longer internally (invisible to the user of boost::thread) query the
> absolute time makes it go away for Windows. And setting the clock condition
> attribute CLOCK_MONOTONIC with POSIX would make it impossible there as far
> as I can tell, does it not?

I've updated the implementation of boost::condition_variable and
boost::condition_variable_any to allow for relative timeouts as well as
absolute timeouts on the predicate version of timed_wait.

On POSIX, the timeouts are always absolute under-the-hood, so a relative
timeout is converted into an absolute one.

On Windows, the relative and absolute timeouts are now treated differently. If
an absolute timeout is specified (using boost::xtime or boost::system_time),
then this is converted into a relative timeout immediately prior to each
internal wait by comparison against the system clock. If the clock is changed,
then this may or may not affect the duration of the wait, depending on whether
the clock change occurred before or after each wait period.

If a relative timeout is specified (using e.g. boost::posix_time::seconds),
then the GetTickCount API is used as a baseline for the relative timeout, and
before each internal wait the current tick count is compared against the
baseline in order to determine the remaining time.

Note that the non-predicate version of timed_wait still only takes an absolute
time, because the potential for spurious wake-ups makes it hard to use
correctly with a relative time, as demonstrated by the bug in APR.

Anthony

-- 
Anthony Williams
Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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