Boost C++ Libraries: Ticket #11322: sleep_for() nanoseconds overload will always return too early on windows https://svn.boost.org/trac10/ticket/11322 <p> We isolated the issue to the following test: </p> <pre class="wiki">#include &lt;boost/thread.hpp&gt; #include &lt;boost/chrono.hpp&gt; int main() { const boost::chrono::nanoseconds SLEEP_DURATION(boost::chrono::milliseconds(500)); const auto SLEEP_DURATION_MS = boost::chrono::duration_cast&lt;boost::chrono::milliseconds&gt;(SLEEP_DURATION); const auto SLEEP_DURATION_US = boost::chrono::duration_cast&lt;boost::chrono::microseconds&gt;(SLEEP_DURATION); const auto SLEEP_DURATION_NANO = boost::chrono::duration_cast&lt;boost::chrono::nanoseconds&gt;(SLEEP_DURATION); const auto SLEEP_DURATION_STEADY = boost::chrono::duration_cast&lt;boost::chrono::steady_clock::duration&gt;(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&lt;boost::chrono::milliseconds&gt;(sleep_duration); const auto sleep_duration_us = boost::chrono::duration_cast&lt;boost::chrono::microseconds&gt;(sleep_duration); const auto sleep_duration_nano = boost::chrono::duration_cast&lt;boost::chrono::nanoseconds&gt;(sleep_duration); assert(sleep_duration &gt;= SLEEP_DURATION); assert(sleep_duration_ms &gt;= SLEEP_DURATION_MS); assert(sleep_duration_us &gt;= SLEEP_DURATION_US); assert(sleep_duration_nano &gt;= SLEEP_DURATION_NANO); } </pre><p> It fails with msvc10. If SLEEP_DURATION is a milliseconds instead of nanoseconds, it runs without failure. </p> <p> 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). </p> <p> It seems that his bug is related to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9720" title="#9720: Bugs: boost::this_thread::sleep_for() sometimes returns immediately on win32 (closed: fixed)">#9720</a> and <a class="new ticket" href="https://svn.boost.org/trac10/ticket/10967" title="#10967: Tasks: Timed wait points inconsistently convert relative to absolute waits (new)">#10967</a> but I'm not sure. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11322 Trac 1.4.3 viboes Fri, 29 May 2015 18:05:45 GMT <link>https://svn.boost.org/trac10/ticket/11322#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11322#comment:1</guid> <description> <p> Could you try the develop branch or boost 1.58? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 28 Jun 2015 09:11:58 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/11322#comment:2 https://svn.boost.org/trac10/ticket/11322#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket jlamotte@… Mon, 29 Jun 2015 10:04:37 GMT <link>https://svn.boost.org/trac10/ticket/11322#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11322#comment:3</guid> <description> <p> So far I didn't find the time to test this with 1.58, sorry. I should be able to test it soon though. </p> </description> <category>Ticket</category> </item> <item> <author>jlamotte@…</author> <pubDate>Tue, 30 Jun 2015 14:22:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11322#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11322#comment:4</guid> <description> <p> I managed to try with Boost 1.58.0 on Windows with MSVC 10.0 (our current compiler) in Debug. </p> <p> So far 1/5 runs will trigger the first assert. So I guess that the bug is still there but is "reduced" in 1.58. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 03 Jul 2015 21:26:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11322#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11322#comment:5</guid> <description> <p> Thanks for trying version 1.58. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 03 Sep 2015 17:23:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11322#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11322#comment:6</guid> <description> <p> Please, could you try commenting the sleep_for on nanoseconds overload in thread/win32/thread_data.hpp </p> <pre class="wiki">#ifdef BOOST_THREAD_USES_CHRONO inline void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds&amp; ns) { interruptible_wait(chrono::duration_cast&lt;chrono::milliseconds&gt;(ns).count()); } #endif </pre> </description> <category>Ticket</category> </item> <item> <author>jlamotte@…</author> <pubDate>Fri, 04 Sep 2015 13:35:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11322#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11322#comment:7</guid> <description> <p> Yes indeed the test pass if I comment this overload. (vs2010 32 bit boost 1.58.0 Debug and Release) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 04 Sep 2015 17:46:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11322#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11322#comment:8</guid> <description> <p> Thanks, I will comment it as well and deliver it to the develop branch. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 05 Sep 2015 14:19:22 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/11322#comment:9 https://svn.boost.org/trac10/ticket/11322#comment:9 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/ac3f7eb0375aae4370d041d0b870c43ab8d5ddc5"><span class="icon">​</span>https://github.com/boostorg/thread/commit/ac3f7eb0375aae4370d041d0b870c43ab8d5ddc5</a> </p> Ticket viboes Sun, 27 Sep 2015 13:41:58 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11322#comment:10 https://svn.boost.org/trac10/ticket/11322#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <blockquote> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/730cb550e6d969520c3f39e0ddf5d80351bddf3a"><span class="icon">​</span>https://github.com/boostorg/thread/commit/730cb550e6d969520c3f39e0ddf5d80351bddf3a</a> </p> </blockquote> Ticket