Boost C++ Libraries: Ticket #9720: boost::this_thread::sleep_for() sometimes returns immediately on win32 https://svn.boost.org/trac10/ticket/9720 <p> I have observed one instance of boost::this_thread::sleep_for returning immediately instead of waiting for the specified time. This happened on a Windows 7 32 bit machine, with Boost 1.55 and VS2012. Another relevant thing might be that it is a VM with 2 cpus running in <a class="missing wiki">XenServer</a> 6.2. </p> <p> Attached is my test program, that starts a bunch of threads that all do a sleep_for(10 minutes). Main then immediately interrupts and joins the threads. The threads all check whether they timed out or whether they were interrupted. In case they time out we print the elapsed time, which of course is expected to be 10 minutes. </p> <p> Here is the output of my test program: </p> <pre class="wiki">first test Timeout! Elapsed time: 0.000039s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) . </pre><p> I'm thinking that this could be something to do with the well known strangeness of <a class="missing wiki">QueryPerformanceCounter</a> (see for example <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8006" title="#8006: Support Requests: Boost::Chrono Assertion at startup - steady_clock::now() - Windows (closed: fixed)">#8006</a>). The VM host was probably under a fair bit of load at the time this test failed. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9720 Trac 1.4.3 Lars Hagström <lars@…> Thu, 27 Feb 2014 09:27:51 GMT attachment set https://svn.boost.org/trac10/ticket/9720 https://svn.boost.org/trac10/ticket/9720 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">BoostSleep_test.cpp</span> </li> </ul> <p> Test of this_thread::sleep_for and interruption. </p> Ticket viboes Thu, 27 Feb 2014 21:37:17 GMT owner, status changed https://svn.boost.org/trac10/ticket/9720#comment:1 https://svn.boost.org/trac10/ticket/9720#comment:1 <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 viboes Thu, 27 Feb 2014 21:41:54 GMT <link>https://svn.boost.org/trac10/ticket/9720#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:2</guid> <description> <p> Please could you rework the example without using boost::timer and using a steady_clock or high_resolution_clock? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 27 Feb 2014 22:02:17 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/9720 https://svn.boost.org/trac10/ticket/9720 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_9720.cpp</span> </li> </ul> <p> Could you try this one using the develop branch? </p> Ticket Lars Hagström <lars@…> Sun, 02 Mar 2014 16:45:56 GMT <link>https://svn.boost.org/trac10/ticket/9720#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:3</guid> <description> <p> I've now got this happening regularly. It appears to only happen at the very start of running the program. So I've rewritten it with just chrono and no timers, and also added a python script that runs it repeatedly. </p> <p> Can be found here (an svn repo): <a class="ext-link" href="http://svn.code.sf.net/p/safir/svn/misc/boost_sleep_test/"><span class="icon">​</span>http://svn.code.sf.net/p/safir/svn/misc/boost_sleep_test/</a> </p> <p> Anyway, this now fails quite quickly on a VM like the one I described above. </p> <pre class="wiki">Timeout! Elapsed time: 601116317640 nanoseconds. </pre><p> Will try with the develop branch "soon" (am home with sick kid atm). </p> </description> <category>Ticket</category> </item> <item> <author>Lars Hagström <lars@…></author> <pubDate>Sun, 02 Mar 2014 20:40:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9720#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:4</guid> <description> <p> I just realized what the problem is! </p> <p> It's not a QPC problem after all. It's the static in steady_clock::now. I've got 50 threads trying to initialize that static variable at the same time, of course things go wrong :-) </p> <p> No idea of how to fix it in an efficient manner, though. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 10 Mar 2014 18:47:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9720#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9720#comment:4" title="Comment 4">Lars Hagström &lt;lars@…&gt;</a>: </p> <blockquote class="citation"> <p> I just realized what the problem is! </p> <p> It's not a QPC problem after all. It's the static in steady_clock::now. I've got 50 threads trying to initialize that static variable at the same time, of course things go wrong :-) </p> <p> No idea of how to fix it in an efficient manner, though. </p> </blockquote> <p> Do you mean the static in </p> <pre class="wiki"> static double nanosecs_per_tic = chrono_detail::get_nanosecs_per_tic(); </pre><p> Could you try removing the static keyword? </p> <pre class="wiki"> steady_clock::time_point steady_clock::now() BOOST_NOEXCEPT { double nanosecs_per_tic = chrono_detail::get_nanosecs_per_tic(); </pre> </description> <category>Ticket</category> </item> <item> <author>Lars Hagström <lars@…></author> <pubDate>Tue, 11 Mar 2014 08:08:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9720#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:6</guid> <description> <p> Yes, that is exactly the one I mean. </p> <p> I've removed the static keyword and it works very well now. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 12 Mar 2014 22:52:28 GMT</pubDate> <title>component, milestone changed https://svn.boost.org/trac10/ticket/9720#comment:7 https://svn.boost.org/trac10/ticket/9720#comment:7 <ul> <li><strong>component</strong> <span class="trac-field-old">thread</span> → <span class="trac-field-new">chrono</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.56.0</span> </li> </ul> Ticket viboes Wed, 12 Mar 2014 22:55:37 GMT <link>https://svn.boost.org/trac10/ticket/9720#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:8</guid> <description> <p> Thanks, I have changed to Chrono. I will propose you a complete patch soon. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 12 Mar 2014 23:48:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9720#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:9</guid> <description> <p> <a class="ext-link" href="https://github.com/boostorg/chrono/commit/318e5f24297977d1bc126d2cd7ac65effe1cb7b7"><span class="icon">​</span>https://github.com/boostorg/chrono/commit/318e5f24297977d1bc126d2cd7ac65effe1cb7b7</a> </p> </description> <category>Ticket</category> </item> <item> <author>Lars Hagström <lars@…></author> <pubDate>Wed, 19 Mar 2014 07:51:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9720#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:10</guid> <description> <p> That certainly works. Thanks! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 27 Apr 2014 13:50:35 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9720#comment:11 https://svn.boost.org/trac10/ticket/9720#comment:11 <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> <p> <a class="ext-link" href="https://github.com/boostorg/chrono/commit/dfb7bc71c9728e5b8e9bbc0679b95a46f4cbb0ba"><span class="icon">​</span>https://github.com/boostorg/chrono/commit/dfb7bc71c9728e5b8e9bbc0679b95a46f4cbb0ba</a> </p> Ticket Smithe329 Sat, 16 Aug 2014 04:07:22 GMT status, severity, type, component, version, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/9720#comment:12 https://svn.boost.org/trac10/ticket/9720#comment:12 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Not Applicable</span> </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Library Submissions</span> </li> <li><strong>component</strong> <span class="trac-field-old">chrono</span> → <span class="trac-field-new">xpressive</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.55.0</span> → <span class="trac-field-new">Boost.Build-M3</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.56.0</span> → <span class="trac-field-new">Website 1.X</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> If you are going for best contents like myself, simply go to see this site all ekebkcegekkdbdde </p> Ticket anonymous Sat, 31 Jan 2015 04:42:18 GMT <link>https://svn.boost.org/trac10/ticket/9720#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:13</guid> <description> <p> When are you guys going to fix it? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 31 Jan 2015 09:59:17 GMT</pubDate> <title>type, version, component, severity, milestone changed https://svn.boost.org/trac10/ticket/9720#comment:14 https://svn.boost.org/trac10/ticket/9720#comment:14 <ul> <li><strong>type</strong> <span class="trac-field-old">Library Submissions</span> → <span class="trac-field-new">Bugs</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost.Build-M3</span> → <span class="trac-field-new">Boost 1.55.0</span> </li> <li><strong>component</strong> <span class="trac-field-old">xpressive</span> → <span class="trac-field-new">thread</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Not Applicable</span> → <span class="trac-field-new">Problem</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Website 1.X</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> Smithe329, we can be wrong when we do some changes on the Trac. This doesn't mean that you don't need to be polite. </p> Ticket viboes Sat, 31 Jan 2015 10:02:54 GMT <link>https://svn.boost.org/trac10/ticket/9720#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9720#comment:15</guid> <description> <p> It seems this is related to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9856" title="#9856: Bugs: [windows] condition_variable::wait_for returns wrong cv_status on timeout. (closed: wontfix)">#9856</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>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 01 Feb 2015 15:23:28 GMT</pubDate> <title>status changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/9720#comment:16 https://svn.boost.org/trac10/ticket/9720#comment:16 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> <p> anonymous please, if this is not working for you give more information. This was fixed as Lars said "That certainly works. Thanks!". </p> Ticket