Boost C++ Libraries: Ticket #7665: this_thread::sleep_for no longer uses steady_clock in thread https://svn.boost.org/trac10/ticket/7665 <p> In 1.51 sleep_for slept for set time no matter what [unless it received interrupt]. In 1.52 sleep_for behaves like normal sleep [system_clock, which introduces problems witch changing time while sleeping] if in new thread. </p> <p> How to reproduce: Compile and run the test. Change time [date -s 10:00:00]. </p> <p> Main thread will exit sleep_for after 10 seconds. Boost::thread will end after some other time. </p> <p> In correct situation [ex. boost 1.51] they should end simultaneously. </p> <p> I think it's introduced in revision 80450. </p> <p> Example program demonstrating this behavior is attached. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7665 Trac 1.4.3 ewdevel@… Thu, 08 Nov 2012 14:40:14 GMT attachment set https://svn.boost.org/trac10/ticket/7665 https://svn.boost.org/trac10/ticket/7665 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sleep_for_test.cpp</span> </li> </ul> <p> Test for sleep_for that fails when time is changed. </p> Ticket viboes Thu, 08 Nov 2012 18:25:30 GMT owner, status changed https://svn.boost.org/trac10/ticket/7665#comment:1 https://svn.boost.org/trac10/ticket/7665#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> <p> Which platform and compiler are you using? </p> Ticket viboes Thu, 08 Nov 2012 21:52:18 GMT <link>https://svn.boost.org/trac10/ticket/7665#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:2</guid> <description> <p> Hi, I have checked your program on <a class="missing wiki">MacOs</a> gcc-4.2.1, and I'm unable to reproduce the behavior you reported </p> <pre class="wiki">gt-s8600:test viboes$ date Jeu 8 nov 2012 22:00:03 CET gt-s8600:test viboes$ ./a.out Main thread START Sleeping for 10 seconds - change time Main thread END Ended gt-s8600:test viboes$ date Jeu 8 nov 2012 10:10:06 CET </pre><p> I have changed the date to 10:10 </p> </description> <category>Ticket</category> </item> <item> <author>Eryk Wieliczko <ewdevel@…></author> <pubDate>Tue, 13 Nov 2012 10:52:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:3</guid> <description> <p> It seems that mac version [guessing from boost/chrono/detail/inlined] uses different sources for time keeping. </p> <p> I've been able to reproduce this bug under: CentOS 6.2 x64 [gcc 4.4.6] <a class="missing wiki">VirtualBox</a>'ed Ubuntu 10.04 x64 [gcc 4.6.1] </p> <p> Can someone check this under different linux distros? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 14 Nov 2012 18:33:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7665#comment:3" title="Comment 3">Eryk Wieliczko &lt;ewdevel@…&gt;</a>: </p> <blockquote class="citation"> <p> It seems that mac version [guessing from boost/chrono/detail/inlined] uses different sources for time keeping. </p> <p> I've been able to reproduce this bug under: CentOS 6.2 x64 [gcc 4.4.6] <a class="missing wiki">VirtualBox</a>'ed Ubuntu 10.04 x64 [gcc 4.6.1] </p> </blockquote> <p> OK I will check. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 25 Nov 2012 09:03:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:5</guid> <description> <p> I don't know if there is a regression in trunk of Boost.Thread on Ubuntu as a lot of tests are failing independently of setting the date. It is surprising that the code is working on Ubuntu 12.04-64 testers. I'll continue the analysis. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 01 Dec 2012 11:42:41 GMT</pubDate> <title>summary, milestone changed https://svn.boost.org/trac10/ticket/7665#comment:6 https://svn.boost.org/trac10/ticket/7665#comment:6 <ul> <li><strong>summary</strong> <span class="trac-field-old">this_thread::sleep_for no longer uses steady_clock in thread</span> → <span class="trac-field-new">l</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.53.0</span> </li> </ul> <p> I've made some changes on the sleep_for algo depending on BOOST_THREAD_SLEEP_FOR_IS_STEADY is defined or not. have you the possibility to check if this rework solves the issue? </p> <p> Committed in trunk <a class="changeset" href="https://svn.boost.org/trac10/changeset/81649" title="Thread: update sleep_for algo depending on whether ...">[81649]</a> </p> Ticket viboes Sat, 01 Dec 2012 11:45:49 GMT summary changed https://svn.boost.org/trac10/ticket/7665#comment:7 https://svn.boost.org/trac10/ticket/7665#comment:7 <ul> <li><strong>summary</strong> <span class="trac-field-old">l</span> → <span class="trac-field-new">sleep_for doesn't use steady_clock</span> </li> </ul> Ticket viboes Sat, 01 Dec 2012 11:46:19 GMT summary changed https://svn.boost.org/trac10/ticket/7665#comment:8 https://svn.boost.org/trac10/ticket/7665#comment:8 <ul> <li><strong>summary</strong> <span class="trac-field-old">sleep_for doesn't use steady_clock</span> → <span class="trac-field-new">this_thread::sleep_for no longer uses steady_clock in thread</span> </li> </ul> Ticket viboes Tue, 11 Dec 2012 22:19:29 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7665#comment:9 https://svn.boost.org/trac10/ticket/7665#comment:9 <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> I hope the modification fixes the bug. Reopen it if you see the issue on 1.53 or on trunk. </p> Ticket Volker_pruess@… Fri, 04 Apr 2014 08:30:19 GMT <link>https://svn.boost.org/trac10/ticket/7665#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:10</guid> <description> <p> I think this needs to become reopened. We observe regression with boost 1.54.0, 1.55.0 and latest git version. Additionally the discussion <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6787" title="#6787: Bugs: boost::thread::sleep() hangs if system time is rolled back (closed: fixed)">#6787</a> also points in this direction. </p> <p> We're using Ubuntu 12.04.4 LTS 64 bit for x86. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 04 Apr 2014 22:08:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:11</guid> <description> <p> And what do you think of the proposition in <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6787" title="#6787: Bugs: boost::thread::sleep() hangs if system time is rolled back (closed: fixed)">#6787</a>? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 04 Apr 2014 22:09:38 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/7665#comment:12 https://svn.boost.org/trac10/ticket/7665#comment:12 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket Volker Prüß <Volker_Pruess@…> Mon, 07 Apr 2014 13:21:10 GMT <link>https://svn.boost.org/trac10/ticket/7665#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:13</guid> <description> <p> I'm not quite sure about the solution you proposed but I see the problem : </p> <ul><li>'boost::this_thread::sleep_for' has to remain an interruption point </li><li>there are no standard library or pthread functions allowing interuptible operation based upon a stable clock, especially for a portable library. </li></ul><p> I checked against the c++ library provided alongside with the gcc 4.6.3 and at least their implementation of sleep_for is not affected by changes in the system clock. It seems that the gcc implementation is based upon nanosleep (<a class="ext-link" href="http://stackoverflow.com/questions/12523122/what-is-glibcxx-use-nanosleep-all-about"><span class="icon">​</span>http://stackoverflow.com/questions/12523122/what-is-glibcxx-use-nanosleep-all-about</a>), IMHO therefore not interruptible. </p> <p> I'm not quite sure whether an implementation of sleep_for (and sleep) that is affected by changes made to the system clock would be acceptable anyway. And moving sleep_for out of the namespace 'this_thread' would break existing code. </p> <p> Seems to be a question for the standard library experts ... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 07 Apr 2014 16:50:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:14</guid> <description> <p> The standard doesn't includes interruptible threads. And Boost can do whatever we decide without the standard library experts advice ;-) </p> <p> So it is up to you to decide if we want additional non-interruptible functions or not. By compatibility, we can not replace the current behavior. </p> </description> <category>Ticket</category> </item> <item> <author>Volker Prüß <Volker_Pruess@…></author> <pubDate>Tue, 08 Apr 2014 07:51:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:15</guid> <description> <p> When you refer to <em>the current behaviour</em> you mean that boost::this_thread::sleep_for has been mentioned in the list of predefined interruption points ? The documentation about sleep_for also says </p> <p> <em>Suspends the current thread until the duration specified by by rel_time has elapsed.</em> </p> <p> Question is which clock is used to measure the <em>duration</em>. I would expect that most programmers would intuitively expect a stable clock here. But referring to the type of clock in the documentation would do it. So I would agree to your suggestion adding another set of methods. </p> </description> <category>Ticket</category> </item> <item> <author>Volker Prüß <Volker_Pruess@…></author> <pubDate>Thu, 10 Apr 2014 08:23:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:16</guid> <description> <p> I saw that sleep_for is using <em>pthread_cond_wait</em> to achieve thread suspension and being interruptible. Is it possible to initialize the condition variable to use the monotonic clock as described <a class="ext-link" href="http://stackoverflow.com/questions/11893992/implementing-condition-variable-timed-wait-correctly"><span class="icon">​</span>here</a> ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 06 Jul 2014 10:13:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:17</guid> <description> <p> I was not aware of pthread_condattr_setclock. I will adapt condition_variable to use it on the platforms providing it. </p> <p> Thanks for the pointer. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 06 Jul 2014 11:17:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:18</guid> <description> <p> Unfortunately pthread_condattr_setclock is not available on <a class="missing wiki">MacOs</a>?. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 07 Sep 2014 07:58:52 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/7665#comment:19 https://svn.boost.org/trac10/ticket/7665#comment:19 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.53.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Wed, 10 Sep 2014 11:50:49 GMT milestone changed https://svn.boost.org/trac10/ticket/7665#comment:20 https://svn.boost.org/trac10/ticket/7665#comment:20 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/02bc292c201e6146ba18e05699d0a5c62f540a5b"><span class="icon">​</span>https://github.com/boostorg/thread/commit/02bc292c201e6146ba18e05699d0a5c62f540a5b</a> </p> Ticket viboes Tue, 16 Sep 2014 06:20:30 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7665#comment:21 https://svn.boost.org/trac10/ticket/7665#comment:21 <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> </ul> Ticket viboes Thu, 03 Sep 2015 20:56:27 GMT status, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/7665#comment:22 https://svn.boost.org/trac10/ticket/7665#comment:22 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.57.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> I'm writing a patch that uses pthread_condattr_setclock. As I said I have no platform providing it (I'm using MacOS). The user will need to define BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC until I find a way to detect it. </p> <p> Is there any one that can test it? </p> Ticket viboes Thu, 03 Sep 2015 21:45:30 GMT milestone changed https://svn.boost.org/trac10/ticket/7665#comment:23 https://svn.boost.org/trac10/ticket/7665#comment:23 <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> Add to develop branch <a class="ext-link" href="https://github.com/boostorg/thread/commit/9f883f6ad7377b88b79fa70cc5de68cbfb0213e4"><span class="icon">​</span>https://github.com/boostorg/thread/commit/9f883f6ad7377b88b79fa70cc5de68cbfb0213e4</a> </p> Ticket viboes Sat, 05 Sep 2015 14:20:33 GMT status changed https://svn.boost.org/trac10/ticket/7665#comment:24 https://svn.boost.org/trac10/ticket/7665#comment:24 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket viboes Sat, 05 Sep 2015 14:23:06 GMT milestone changed https://svn.boost.org/trac10/ticket/7665#comment:25 https://svn.boost.org/trac10/ticket/7665#comment:25 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.60.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Tue, 08 Sep 2015 19:43:19 GMT status changed https://svn.boost.org/trac10/ticket/7665#comment:26 https://svn.boost.org/trac10/ticket/7665#comment:26 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Wed, 23 Sep 2015 23:03:17 GMT <link>https://svn.boost.org/trac10/ticket/7665#comment:27 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:27</guid> <description> <p> Please could you try to replace in thread/v2/thread.hpp line <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/94" title="#94: Tasks: Better reporting of failed expectation. (closed: wontfix)">#94</a> </p> <p> #ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY </p> <p> by </p> <p> #if defined BOOST_THREAD_SLEEP_FOR_IS_STEADY &amp;&amp; ! defined BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 25 Sep 2015 05:40:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:28 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:28</guid> <description> <p> Please, could you try the develop branch </p> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/8f5de1d7c34ff7248261874f273498a622bf76d4"><span class="icon">​</span>https://github.com/boostorg/thread/commit/8f5de1d7c34ff7248261874f273498a622bf76d4</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 25 Sep 2015 05:43:12 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/7665#comment:29 https://svn.boost.org/trac10/ticket/7665#comment:29 <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> Ticket mail@… Fri, 25 Sep 2015 22:40:04 GMT <link>https://svn.boost.org/trac10/ticket/7665#comment:30 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:30</guid> <description> <p> I'm experiencing the same problem (Linux Mint, 3.13.0-37-generic # 64-Ubuntu SMP, boost 1.54). </p> <p> Can confirm that the threads are behaving differently with the test code. </p> <p> Checked out modular-boost, switched to develop for boost-thread, compiled everything and tried the test code above. Adding </p> <p> #define BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC 1 </p> <p> fixes the bug for me. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 27 Sep 2015 12:22:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7665#comment:31 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7665#comment:31</guid> <description> <p> Thanks for the report. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 27 Sep 2015 13:40:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7665#comment:32 https://svn.boost.org/trac10/ticket/7665#comment:32 <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