Boost C++ Libraries: Ticket #8960: condition_wariable::wait_for throws exception (with Invalid argument), if system date/time < 1970 https://svn.boost.org/trac10/ticket/8960 <p> Linux, kernel 2.6.32, arm-none-linux-gnueabi-g++ 2010q1 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8960 Trac 1.4.3 albel78@… Sat, 03 Aug 2013 14:52:34 GMT <link>https://svn.boost.org/trac10/ticket/8960#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8960#comment:1</guid> <description> <p> example: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/thread.hpp&gt; #include &lt;boost/thread/locks.hpp&gt; #include &lt;boost/chrono.hpp&gt; #include &lt;boost/bind.hpp&gt; void do_thread(){ try{ boost::condition_variable c1; boost::mutex m1; boost::unique_lock&lt;boost::mutex&gt; l1(m1); c1.wait_for(l1,boost::chrono::seconds(1)); } catch(std::runtime_error&amp; ex){ std::cout&lt;&lt;"EXCEPTION ! "&lt;&lt;ex.what()&lt;&lt;std::endl; } } int main(int argc,char** argv){ boost::thread th1(&amp;do_thread); std::string s1; std::cin&gt;&gt;s1; return -1; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 03 Aug 2013 16:10:11 GMT</pubDate> <title>status, component changed; owner set https://svn.boost.org/trac10/ticket/8960#comment:2 https://svn.boost.org/trac10/ticket/8960#comment:2 <ul> <li><strong>owner</strong> set 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> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">thread</span> </li> </ul> Ticket viboes Sat, 03 Aug 2013 16:29:53 GMT <link>https://svn.boost.org/trac10/ticket/8960#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8960#comment:3</guid> <description> <p> The example works fine for me on trunk. Could you try the trunk or the lasr 1.54 version? </p> </description> <category>Ticket</category> </item> <item> <author>albel78@…</author> <pubDate>Sat, 03 Aug 2013 19:27:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8960#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8960#comment:4</guid> <description> <p> have some problems to reproduce, because busybox applet 'date' has builtin value check, and set system date to any value &lt; 01-01-1970 is currently impossible. </p> <p> this issue caused on development board (D2-plug,<a class="ext-link" href="http://www.globalscaletechnologies.com/t-d2plugdetails.aspx"><span class="icon">​</span>http://www.globalscaletechnologies.com/t-d2plugdetails.aspx</a>) </p> <p> I don't know about a reason, but 3 days ago system time was changed to May 1948. (rtc chip, or something else - i don't know). Then i catched exceptions on condition_variables. Then long time debugging, and i find reason of EINVAL of pthread_cond_timed_wait: bad value of timespec (big negative value of tv_sec), which is result of this code (pthread/condition_variable.hpp): </p> <pre class="wiki"> template &lt;class lock_type, class Clock, class Duration&gt; cv_status wait_until( lock_type&amp; lock, const chrono::time_point&lt;Clock, Duration&gt;&amp; t) { using namespace chrono; system_clock::time_point s_now = system_clock::now(); typename Clock::time_point c_now = Clock::now(); wait_until(lock, s_now + ceil&lt;nanoseconds&gt;(t - c_now)); return Clock::now() &lt; t ? cv_status::no_timeout : cv_status::timeout; } </pre><p> and one notice: exceptions throws only in child threads. condvars in main thread workes fine. </p> <p> now i correct system time to 2013, and all is ok. </p> <p> if you tell me easy way to set up May 1948 - i'm ready for any tests. </p> <p> (sorry for my english) Alexey. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 04 Aug 2013 08:15:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8960#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8960#comment:5</guid> <description> <p> I suspect that I can not do anything for this case, if pthread_cond_timed_wait doesn't supports times before 01-01-1970. </p> <p> What do you suggest? </p> </description> <category>Ticket</category> </item> <item> <author>albel78@…</author> <pubDate>Sun, 04 Aug 2013 10:01:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8960#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8960#comment:6</guid> <description> <p> I suggest: check for negative timespec::tv_sec and throw different exception, than "phread_cond_timed_wait: EINVAL" </p> <p> debug of this issue may be not simple, if boost::condition_variable::wait_for do not called directly. In my case - exception throws from boost::this_thread::sleep_for (in child threads). And code was absolutely not ready for this surprise. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 09 Aug 2013 06:31:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8960#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8960#comment:7</guid> <description> <p> I don't know if it is worth including this on the library. </p> <p> You could do this kind of test yourself. You can wrap the sleep_for call and do the test there. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 22 Aug 2013 22:03:48 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8960#comment:8 https://svn.boost.org/trac10/ticket/8960#comment:8 <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> Ticket