Subject: Re: [Boost-bugs] [Boost C++ Libraries] #11331: boost::this_thread::sleep_for does not sleep for requested time
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-05-24 21:33:27
#11331: boost::this_thread::sleep_for does not sleep for requested time
------------------------------------------+-----------------------
Reporter: Scott Minor <scott.minor@â¦> | Owner: ned14
Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
Version: Boost 1.58.0 | Severity: Problem
Resolution: | Keywords: sleep_for
------------------------------------------+-----------------------
Comment (by ned14):
Replying to [comment:3 scott.minor.13@â¦]:
> Thanks for the follow-up. How would you recommend users of Boost 1.58
rewrite their algorithms if they are impacted by this behavior?
Depends on the algorithm. 95% of the time if you need to wait for exactly
30 seconds down to the millisecond, there is something very wrong with
your assumptions because that is only ever somewhat likely on a non-
realtime OS, or any system able to swap memory onto disc.
For example, if you actually merely need to poll something every thirty
seconds, what you do is to adjust subsequent timeouts for when some
timeout is late, and you aim for 120 wakeups per hour, not a sleep of 30
seconds each. You obviously need to adjust readings according to wakeup
error. This is the kind of thing engineers ought to do from the beginning,
but it's just hugely easier not to.
Another strategy is you sleep 80% of 30 seconds, then enter a yield loop
for another 10%, then a spin loop for the remaining 10% - this delivers
microsecond accurate sleeps most of the time. For any occasions where the
OS context switches at exactly the wrong moment you still need a method of
detecting the error and throwing away/retrying the exact wait.
Niall
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11331#comment:4> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC