|
Boost : |
Subject: Re: [boost] [thread] Timed waits in Boost.Thread potentially fundamentally broken on Windows (possibly rest of Boost too)
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2015-01-24 09:18:13
On 23 Jan 2015 at 18:30, Andrey Semashev wrote:
> > Vista made these changes to scheduling for efficiency purposes. I
> > suspect Boost.Thread was written for an XP or earlier target.
>
> I'm confused. Boost.Thread always implemented the standard behavior, with
> possibility of spurious wakeups. Windows before Vista did not exhibit spurious
> wakeups (which was ok) and since Vista it started doing this, and this
> improved efficiency (I assume, the estimate of the improvement had included
> the negative effect on the applications dealing with the wakeups).
> Boost.Thread is still behaving correctly wrt the standard. So, why would you
> want to change Boost.Thread and conceal spurious wakeups, making it less
> efficient? I'll reiterate that any current use of cv must deal with spurious
> wakeups already.
Firstly, my thanks to both you and Peter for your thoughts on this.
After sleeping on it for a night, this is what I'll do: I'm going to
update Thread's clamping of timeouts to better match Windows since
Vista onwards. This basically means asking Windows what its current
scheduling quantum is (it can vary from moment to moment according to
what applications request) and clamping the timeout sent to Windows
APIs to that quantum. Therefore, if you asked for a 10ms timeout,
Thread will clamp that probably to 15 ms before sending it onto
Windows. I'll always round upwards, so there is a greater potential
for a timed wait to take one quantum longer than it should before
timing out, but then that can happen anyway at any time.
None of this will remove spurious wakeups, but it will reduce their
frequency considerably. It means that the CPU spends more time
sleeping and less being woken up and being put back to sleep by a
predicate check loop.
If anyone has a problem with this solution, now is the time to speak.
Niall
-- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk