Boost C++ Libraries: Ticket #8768: win32 condition_variable::wait_until infinite wait in rare cases https://svn.boost.org/trac10/ticket/8768 <p> on win32 platform <code> condition_variable::wait_until(lk, t) </code> can wait infinite long if </p> <div class="wiki-code"><div class="code"><pre><span class="n">ceil</span><span class="o">&lt;</span><span class="n">milliseconds</span><span class="o">&gt;</span><span class="p">(</span><span class="n">t</span> <span class="o">-</span> <span class="n">t</span><span class="o">::</span><span class="n">clock</span><span class="o">::</span><span class="n">now</span><span class="p">()).</span><span class="n">count</span><span class="p">()</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span> </pre></div></div><p> do_wait takes boost::detail::timeout. It constructs from -1 =&gt; boost::detail::timeout::milliseconds == 0xf..ff, witch is a special value checked by is_sentinel(). </p> <p> Later in win32/thread.cpp: this_thread::interruptible_wait code waits boost::detail::timeout::max_non_infinite_wait. </p> <p> tested it with msvs 2010. </p> <p> attached example </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8768 Trac 1.4.3 Dmitry Lysachenko <xdemonx07@…> Wed, 03 Jul 2013 08:03:05 GMT attachment set https://svn.boost.org/trac10/ticket/8768 https://svn.boost.org/trac10/ticket/8768 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">wait_until-example.cpp</span> </li> </ul> <p> repro example </p> Ticket viboes Wed, 03 Jul 2013 10:52:30 GMT owner, status changed https://svn.boost.org/trac10/ticket/8768#comment:1 https://svn.boost.org/trac10/ticket/8768#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, 22 Aug 2013 22:18:09 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8768#comment:2 https://svn.boost.org/trac10/ticket/8768#comment:2 <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">wontfix</span> </li> </ul> <p> The example is to rare to take care of it. </p> Ticket szakharchenko@… Sat, 24 Aug 2013 07:30:28 GMT <link>https://svn.boost.org/trac10/ticket/8768#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8768#comment:3</guid> <description> <p> This isn't at all rare, for example, it's the final cause of my problems in <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8323" title="#8323: Bugs: boost::thread::try_join_for/try_join_until may block indefinitely due ... (closed: fixed)">#8323</a> (the current ticket's author just made it easier to reproduce, and his analysis is more correct than mine). That is, code hitting this problem from time to time can easily be written, and it is extremely hard to find the problem, unless you know that such waits can turn out to be infinite. </p> </description> <category>Ticket</category> </item> <item> <author>s.heil@…</author> <pubDate>Tue, 03 Sep 2013 11:56:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8768#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8768#comment:4</guid> <description> <p> We ran into this problem as well and after a lot of debugging, we found this ticket. In our case we got bit by that problem in production code, so we really hope it will get fixed. We also have a simple test, that in about 7 of 10 runs reproduces the problem: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/thread.hpp&gt; #include &lt;boost/chrono.hpp&gt; using namespace std; int main( int argc, const char* argv[] ) { boost::mutex mutex; boost::condition_variable variable; boost::unique_lock&lt;boost::mutex&gt; lock( mutex ); for ( int i = 5; i &gt;= - 10; i -- ) { boost::chrono::time_point&lt;boost::chrono::steady_clock&gt; time = boost::chrono::steady_clock::now() + boost::chrono::milliseconds( i ); std::cerr &lt;&lt; "test " &lt;&lt; i &lt;&lt; ": " &lt;&lt; " ... "; variable.wait_until( lock, time ); std::cerr &lt;&lt; "ok" &lt;&lt; std::endl; } } </pre><p> The only solution we see right now is to not ever use wait_until, as it might block forever. So we are replacing all calls to wait_until in our code with calls to wait_for. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 03 Sep 2013 21:01:19 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/8768#comment:5 https://svn.boost.org/trac10/ticket/8768#comment:5 <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">wontfix</span> </li> </ul> <p> Hi, </p> <p> I think that <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9079" title="#9079: Bugs: Condition variable will wait forever for some timepoint values (MSVC) (closed: fixed)">#9079</a> includes two examples that are realistic and that seems to have the same issue. </p> <p> I will try to fix it soon. </p> Ticket viboes Sat, 07 Sep 2013 12:15:46 GMT milestone changed https://svn.boost.org/trac10/ticket/8768#comment:6 https://svn.boost.org/trac10/ticket/8768#comment:6 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.55.0</span> </li> </ul> <p> Please, could you try after updating with the following </p> <p> Changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/85591" title="Thread: protect condition_variable/_any wait_for and wait_until from ...">[85591]</a>,<a class="changeset" href="https://svn.boost.org/trac10/changeset/85592" title="Thread: protect condition_variable/_any wait_for and wait_until from ...">[85592]</a> </p> <blockquote> <p> Thread: protect condition_variable/_any wait_for and wait_until from … </p> </blockquote> Ticket viboes Fri, 13 Sep 2013 19:04:57 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8768#comment:7 https://svn.boost.org/trac10/ticket/8768#comment:7 <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> <p> Committed revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/85663" title="Thread: merge scoped_thread constr + condition_variable timed wait ...">[85663]</a>. </p> Ticket