title: Boost.Thread wakes up too late in 1.58
body: <p>I have an application that needs to do work within certain windows (in this case, the windows are all 30 seconds apart). When the time is not within a window, the time until the middle of the next window is calculated, and the thread sleeps for that amount of time (in milliseconds, using <code>boost::this_thread::sleep_for</code>).</p>
  
  <p>Using Boost 1.55, I was able to hit the windows within my tolerance (+/-100ms) with extreme reliability. Upon migration to Boost 1.58, I am never able to hit these windows. Replacing the <code>boost::this_thread::sleep_for</code> with <code>std::this_thread::sleep_for</code> fixes the issue; however, I need the interruptible feature of <code>boost::thread</code> and the interruption point that <code>boost::this_thread::sleep_for</code> provides.</p>
  
  <p>Here is some sample code illustrating the issue:</p>
  
  <pre><code>#include &lt;boost/thread.hpp&gt;
  #include &lt;boost/chrono.hpp&gt;
  
  #include &lt;chrono&gt;
  #include &lt;iostream&gt;
  #include &lt;thread&gt;
  
  void boostThreadFunction ()
  {
     std::cout &lt;&lt; "Starting Boost thread" &lt;&lt; std::endl;
     for (int i = 0; i &lt; 10; ++i)
     {
        auto sleep_time = boost::chrono::milliseconds {29000 + 100 * i};
        auto mark = std::chrono::steady_clock::now ();
        boost::this_thread::sleep_for (sleep_time);
        auto duration = std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(
           std::chrono::steady_clock::now () - mark);
        std::cout &lt;&lt; "Boost thread:" &lt;&lt; std::endl;
        std::cout &lt;&lt; "\tSupposed to sleep for:\t" &lt;&lt; sleep_time.count () 
                  &lt;&lt; " ms" &lt;&lt; std::endl;
        std::cout &lt;&lt; "\tActually slept for:\t" &lt;&lt; duration.count () 
                  &lt;&lt; " ms" &lt;&lt; std::endl &lt;&lt; std::endl;
     }
  }
  
  void stdThreadFunction ()
  {
     std::cout &lt;&lt; "Starting Std thread" &lt;&lt; std::endl;
     for (int i = 0; i &lt; 10; ++i)
     {
        auto sleep_time = std::chrono::milliseconds {29000 + 100 * i};
        auto mark = std::chrono::steady_clock::now ();
        std::this_thread::sleep_for (sleep_time);
        auto duration = std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(
           std::chrono::steady_clock::now () - mark);
        std::cout &lt;&lt; "Std thread:" &lt;&lt; std::endl;
        std::cout &lt;&lt; "\tSupposed to sleep for:\t" &lt;&lt; sleep_time.count () 
                  &lt;&lt; " ms" &lt;&lt; std::endl;
        std::cout &lt;&lt; "\tActually slept for:\t" &lt;&lt; duration.count () 
                  &lt;&lt; " ms" &lt;&lt; std::endl &lt;&lt; std::endl;
     }
  }
  
  int main ()
  {
     boost::thread boost_thread (&amp;boostThreadFunction);
     std::this_thread::sleep_for (std::chrono::seconds (10));
     std::thread std_thread (&amp;stdThreadFunction);
     boost_thread.join ();
     std_thread.join ();
     return 0;
  }
  </code></pre>
  
  <p>Here is the output when referencing Boost 1.58 as an include directory and running on my workstation (Windows 7 64-bit):</p>
  
  <pre><code>Starting Boost thread
  Starting Std thread
  Boost thread:
          Supposed to sleep for:  29000 ms
          Actually slept for:     29690 ms
  
  Std thread:
          Supposed to sleep for:  29000 ms
          Actually slept for:     29009 ms
  
  Boost thread:
          Supposed to sleep for:  29100 ms
          Actually slept for:     29999 ms
  
  Std thread:
          Supposed to sleep for:  29100 ms
          Actually slept for:     29111 ms
  
  Boost thread:
          Supposed to sleep for:  29200 ms
          Actually slept for:     29990 ms
  
  Std thread:
          Supposed to sleep for:  29200 ms
          Actually slept for:     29172 ms
  
  Boost thread:
          Supposed to sleep for:  29300 ms
          Actually slept for:     30005 ms
  
  Std thread:
          Supposed to sleep for:  29300 ms
          Actually slept for:     29339 ms
  
  Boost thread:
          Supposed to sleep for:  29400 ms
          Actually slept for:     30003 ms
  
  Std thread:
          Supposed to sleep for:  29400 ms
          Actually slept for:     29405 ms
  
  Boost thread:
          Supposed to sleep for:  29500 ms
          Actually slept for:     29999 ms
  
  Std thread:
          Supposed to sleep for:  29500 ms
          Actually slept for:     29472 ms
  
  Boost thread:
          Supposed to sleep for:  29600 ms
          Actually slept for:     29999 ms
  
  Std thread:
          Supposed to sleep for:  29600 ms
          Actually slept for:     29645 ms
  
  Boost thread:
          Supposed to sleep for:  29700 ms
          Actually slept for:     29998 ms
  
  Std thread:
          Supposed to sleep for:  29700 ms
          Actually slept for:     29706 ms
  
  Boost thread:
          Supposed to sleep for:  29800 ms
          Actually slept for:     29998 ms
  
  Std thread:
          Supposed to sleep for:  29800 ms
          Actually slept for:     29807 ms
  
  Boost thread:
          Supposed to sleep for:  29900 ms
          Actually slept for:     30014 ms
  
  Std thread:
          Supposed to sleep for:  29900 ms
          Actually slept for:     29915 ms
  </code></pre>
  
  <p>I would expect the <code>std::thread</code> and the <code>boost::thread</code> to sleep for the same amount of time; however, the <code>boost::thread</code> seems to want to sleep for ~30 seconds when asked to sleep for 29.1 - 29.9 seconds. Am I misusing the <code>boost::thread</code> interface, or is this a bug that was introduced since 1.55?</p>