Boost C++ Libraries: Ticket #9618: try_join_for problem: program is not terminate. https://svn.boost.org/trac10/ticket/9618 <p> In the following, </p> <pre class="wiki"> auto pDummyThread = []{ // not important }; boost::thread t1( pDummyThread ); while( true ) { if ( t1.try_join_for(boost::chrono::milliseconds(0))/*(1)*/ ) break; } </pre><p> If (1) is "try_join_for(boost::chrono::millseconds(1))", program will terminate. </p> <p> But (1) is "try_join_for(boost::chrono::milliseconds(0))", program is not terminate. </p> <p> I think that this program must terminate. </p> <p> (boost 1.55.0, windows 8.1 64 bits, Visual Studio 2012) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9618 Trac 1.4.3 viboes Thu, 30 Jan 2014 22:12:32 GMT owner, status changed https://svn.boost.org/trac10/ticket/9618#comment:1 https://svn.boost.org/trac10/ticket/9618#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, 30 Jan 2014 22:26:04 GMT <link>https://svn.boost.org/trac10/ticket/9618#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:2</guid> <description> <pre class="wiki">try_join_for(boost::chrono::milliseconds(0)) </pre><p> will return always false, as the duration time is already elapsed. </p> <p> Why do you think that it could return true? </p> </description> <category>Ticket</category> </item> <item> <author>tkuman@…</author> <pubDate>Thu, 30 Jan 2014 23:27:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:3</guid> <description> <p> I think that the thread of execution has completed even if the duration time is 0, so the function must return true. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 31 Jan 2014 20:15:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:4</guid> <description> <p> HI, next follows an extract of the description I found in <a class="ext-link" href="http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_cond_wait.html"><span class="icon">​</span>http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_cond_wait.html</a>. </p> <p> "The pthread_cond_timedwait() function shall be equivalent to pthread_cond_wait(), except that an error is returned if the absolute time specified by abstime passes (that is, system time equals or exceeds abstime) before the condition cond is signaled or broadcasted, or if the absolute time specified by abstime has already been passed at the time of the call." </p> <p> I don't know how to implement what you are requesting. </p> <p> Why do you want to wait for 0 milliseconds? </p> </description> <category>Ticket</category> </item> <item> <author>tkuman@…</author> <pubDate>Sat, 01 Feb 2014 07:50:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9618#comment:4" title="Comment 4">viboes</a>: </p> <p> 2 reasons. </p> <ol><li>Computer dependent value </li></ol><p> </p> <blockquote> <p> Currently, a millisecond is enough time for "try_join_for" at my computer. But in the future, a millisecond may not be enough time for more faster computer. Therefore, current specification causes instability. The duration time must be computer independent value and it will be specified 0. </p> </blockquote> <ol start="2"><li>Unnecessary redundant work </li></ol><blockquote> <p> Every "try_join_for" call consumes time. It is a possibility that some case may not tolerant the redundant time. </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 01 Feb 2014 12:08:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:6</guid> <description> <p> What you are looking for id try_join() and this doesn't exists and don't know how to implement it. </p> <p> You can also use nanoseconds(1) or attoseconds=duration&lt;intmax_t, atto&gt;. </p> </description> <category>Ticket</category> </item> <item> <author>oniprog <tkuman@…></author> <pubDate>Sat, 01 Feb 2014 14:46:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9618#comment:6" title="Comment 6">viboes</a>: </p> <p> I'm sorry. I'm wrong. </p> <p> Could you make "try_join()" function by using (something like) "try_join_for(chrono::nanoseconds(1))"? </p> <p> I think that it is only (something like) syntax sugar. </p> <p> But I become very happy if I get the function. </p> <p> (And if could, could you teach me some url or something why "chrono::milliseconds(0)" is wrong and impossible? I'm sorry for my ignorance.. ) </p> <p> Thank you for reading. </p> </description> <category>Ticket</category> </item> <item> <author>oniprog <tkuman@…></author> <pubDate>Sun, 02 Feb 2014 12:04:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:8</guid> <description> <p> A kind person teach me about <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>. </p> <p> My understandings are as follows. </p> <ol><li>Before boost 1.54, "try_join_for(chorno::milliseconds(0))" is NG in some multicore machine because timer sometimes is not monotonic. (My machine was luckily OK..) </li></ol><ol start="2"><li>To avoid this problem, the duration time 0 must be avoid. </li></ol><p> (3. Therefore my program behaviour became strange after installing boost 1.55). </p> <p> I hope that something like "argument rel_time cannot be 0" will be written in document explicity for the person who is not good at English like me. </p> <p> I'm sorry for taking your time. </p> <p> Thank you very much. </p> </description> <category>Ticket</category> </item> <item> <author>oniprog <tkuman@…></author> <pubDate>Mon, 03 Feb 2014 12:25:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:9</guid> <description> <p> I found that my program sometimes hang up even if "try_join_for(chrono::milliseconds(1))" uses in my environment... </p> <p> I found that rel_time sometimes become -1.... in my windows 8.1 64 bits environment. </p> <p> I modified the program. </p> <p> boost/thread/detail/thread.hpp </p> <pre class="wiki"> bool try_join_until(const chrono::time_point&lt;chrono::system_clock, chrono::nanoseconds&gt;&amp; tp) { chrono::milliseconds rel_time= chrono::ceil&lt;chrono::milliseconds&gt;(tp-chrono::system_clock::now()); return do_try_join_until(rel_time.count()); } </pre><p> replace with </p> <pre class="wiki"> bool try_join_until(const chrono::time_point&lt;chrono::system_clock, chrono::nanoseconds&gt;&amp; tp) { chrono::milliseconds rel_time= chrono::ceil&lt;chrono::milliseconds&gt;(tp-chrono::system_clock::now()); if ( rel_time &lt; chrono::milliseconds::zero()) // rel_time must not be minus. rel_time= chrono::milliseconds::zero(); return do_try_join_until(rel_time.count()); } </pre><p> I am not confident that this is OK because I don't have exact (academic) knowledge about thread. </p> <p> Is this modification OK? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 09 Feb 2014 03:21:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:10</guid> <description> <p> I have not a windows machine at hand. Please could you try this patch </p> <pre class="wiki">git diff include/boost/thread/detail/thread.hpp diff --git a/include/boost/thread/detail/thread.hpp b/include/boost/thread/detail/thread.hpp index 5053b8d..64804f9 100644 --- a/include/boost/thread/detail/thread.hpp +++ b/include/boost/thread/detail/thread.hpp @@ -464,11 +464,20 @@ namespace boost inline void join(); #ifdef BOOST_THREAD_USES_CHRONO +#if defined(BOOST_THREAD_PLATFORM_WIN32) + template &lt;class Rep, class Period&gt; + bool try_join_for(const chrono::duration&lt;Rep, Period&gt;&amp; rel_time) + { + chrono::milliseconds rel_time2= chrono::ceil&lt;chrono::milliseconds&gt;(rel_time); + return do_try_join_until(rel_time2.count()); + } +#else template &lt;class Rep, class Period&gt; bool try_join_for(const chrono::duration&lt;Rep, Period&gt;&amp; rel_time) { return try_join_until(chrono::steady_clock::now() + rel_time); } +#endif template &lt;class Clock, class Duration&gt; bool try_join_until(const chrono::time_point&lt;Clock, Duration&gt;&amp; t) { </pre> </description> <category>Ticket</category> </item> <item> <author>tkuman@…</author> <pubDate>Tue, 11 Feb 2014 07:27:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:11</guid> <description> <p> I applied the patch. My program works fine!. </p> <p> Thank you very much. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 16 Feb 2014 09:26:29 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/9618#comment:12 https://svn.boost.org/trac10/ticket/9618#comment:12 <ul> <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 Sun, 16 Feb 2014 09:54:06 GMT <link>https://svn.boost.org/trac10/ticket/9618#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:13</guid> <description> <p> See also <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9654" title="#9654: Bugs: try_join_for(0) returns false when thread has exited (closed: duplicate)">#9654</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 16 Feb 2014 09:54:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9618#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9618#comment:14</guid> <description> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/e1636bdbd50f4ec64ba6d92fbf9b493821a4a780"><span class="icon">​</span>https://github.com/boostorg/thread/commit/e1636bdbd50f4ec64ba6d92fbf9b493821a4a780</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 12 Mar 2014 22:48:26 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9618#comment:15 https://svn.boost.org/trac10/ticket/9618#comment:15 <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> Ticket