Re: [Boost-bugs] [Boost C++ Libraries] #6787: boost::thread::sleep() hangs if system time is rolled back

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6787: boost::thread::sleep() hangs if system time is rolled back
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-12-10 16:13:51


#6787: boost::thread::sleep() hangs if system time is rolled back
-----------------------------------------------+----------------------
  Reporter: Artem Gayardo-Matrosov <boost@…> | Owner: viboes
      Type: Bugs | Status: reopened
 Milestone: Boost 1.57.0 | Component: thread
   Version: Boost 1.49.0 | Severity: Problem
Resolution: | Keywords:
-----------------------------------------------+----------------------

Comment (by Matulis):

 Here is some test code that modifies the system time backwards by 1
 minute, however you need to run it as sudo/root, due to the use of stime.
 I link to boost_chrono, so I don't have to create edge cases for when the
 hour/day/month changes.

 Expected Result: Loop in thread should continuously keep printing out
 messages

 Actual Result: After system time is changed, the loop does not execute
 until system time catches back up to present time

 If I have time later, I could try to integrate it into the unit tests, let
 me know if that would be useful.

 {{{
 #!cpp

 #include <iostream>
 #include <time.h>

 #include <boost/thread.hpp>
 #include <boost/chrono.hpp>




 void testfunc() {

         int i = 0;
         while(true) {
                 std::cout << "Testing: " << i << std::endl;
                 boost::this_thread::no_interruption_point::sleep_for(
 boost::chrono::milliseconds(1000));
                 i++;
         }
 }

 int main() {

         boost::thread th = boost::thread(&testfunc);

         //Sleep thread to allow other thread to run for a bit before time
 is changed
         boost::this_thread::sleep_for(boost::chrono::milliseconds(5000));


         boost::chrono::time_point<boost::chrono::system_clock> current =
 boost::chrono::system_clock::now();

         //Set time back 1 minute
         current.operator -=(boost::chrono::minutes(1));

         //Create std time structure from boost chrono
         std::time_t now = boost::chrono::system_clock::to_time_t(current);

         //Set the system time
         stime(&now);

         th.join();

         return 0;
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6787#comment:29>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC