Subject: [Boost-bugs] [Boost C++ Libraries] #11322: sleep_for() nanoseconds overload will always return too early on windows
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-05-19 14:46:27
#11322: sleep_for() nanoseconds overload will always return too early on windows
------------------------------+-------------------------
Reporter: jlamotte@⦠| Owner: anthonyw
Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
Version: Boost 1.55.0 | Severity: Showstopper
Keywords: |
------------------------------+-------------------------
We isolated the issue to the following test:
{{{
#include <boost/thread.hpp>
#include <boost/chrono.hpp>
int main()
{
const boost::chrono::nanoseconds
SLEEP_DURATION(boost::chrono::milliseconds(500));
const auto SLEEP_DURATION_MS =
boost::chrono::duration_cast<boost::chrono::milliseconds>(SLEEP_DURATION);
const auto SLEEP_DURATION_US =
boost::chrono::duration_cast<boost::chrono::microseconds>(SLEEP_DURATION);
const auto SLEEP_DURATION_NANO =
boost::chrono::duration_cast<boost::chrono::nanoseconds>(SLEEP_DURATION);
const auto SLEEP_DURATION_STEADY =
boost::chrono::duration_cast<boost::chrono::steady_clock::duration>(SLEEP_DURATION);
const auto begin = boost::chrono::steady_clock::now();
boost::this_thread::sleep_for(SLEEP_DURATION);
const auto end = boost::chrono::steady_clock::now();
const auto sleep_duration = end - begin;
const auto sleep_duration_ms =
boost::chrono::duration_cast<boost::chrono::milliseconds>(sleep_duration);
const auto sleep_duration_us =
boost::chrono::duration_cast<boost::chrono::microseconds>(sleep_duration);
const auto sleep_duration_nano =
boost::chrono::duration_cast<boost::chrono::nanoseconds>(sleep_duration);
assert(sleep_duration >= SLEEP_DURATION);
assert(sleep_duration_ms >= SLEEP_DURATION_MS);
assert(sleep_duration_us >= SLEEP_DURATION_US);
assert(sleep_duration_nano >= SLEEP_DURATION_NANO);
}
}}}
It fails with msvc10.
If SLEEP_DURATION is a milliseconds instead of nanoseconds, it runs
without failure.
Stepping in the code shows that the nanoseconds sleep_for() overload does
not use a condition variable like the other template sleep_for overloads,
which leads to that bug where the sleep took less time than asked (instead
of equal or more).
It seems that his bug is related to #9720 and #10967 but I'm not sure.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11322> 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