Boost C++ Libraries: Ticket #3178: Sleep with negative time https://svn.boost.org/trac10/ticket/3178 <p> When trying to sleep with a negative timespan it will result in almost infinite sleep. </p> <p> Solution: in this_thread sleep, check for negative timespan before calling interruptible_wait. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3178 Trac 1.4.3 viboes Sun, 29 Nov 2009 20:56:03 GMT <link>https://svn.boost.org/trac10/ticket/3178#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3178#comment:1</guid> <description> <p> As you state this is a regression, could you state on which version this was OK? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Thu, 04 Feb 2010 18:13:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3178#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3178#comment:2</guid> <description> <p> I've got to concur with the OP (from libs/thread/win32/thread_data.hpp): </p> <pre class="wiki"> namespace this_thread { template&lt;typename TimeDuration&gt; inline void sleep(TimeDuration const&amp; rel_time) { interruptible_wait(static_cast&lt;unsigned long&gt;(rel_time.total_milliseconds())); } } </pre><p> The problem here is the cast to unsigned long; that turns a small negative value into a large positive one. The question is, what should happen? Should the fn return immediately? Throw an exception? </p> <p> On the pthread side, the code looks like: </p> <pre class="wiki"> namespace this_thread { inline void sleep(TimeDuration const&amp; rel_time) { this_thread::sleep(get_system_time()+rel_time); } } </pre><p> I don't know what happens if you pass a time in the past to sleep here, but the same questions as to how to handle the error apply. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 21 May 2010 16:08:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3178#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3178#comment:3</guid> <description> <p> I don't think the low level functions must check for these on the past wait, for me this should be undefined behavior (the documentation should state this for all the timeout based operation). The user can always define its own function that do the check. If people consider that this is useful we could add some safe timeout based functions. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Anthony Williams</dc:creator> <pubDate>Fri, 21 May 2010 17:00:17 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3178#comment:4 https://svn.boost.org/trac10/ticket/3178#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed on trunk. </p> Ticket