title: How to sleep for a fixed period of time not affected by system clock adjustment in Visual C++ 2012
body: <p>I was using <code>std::this_thread::sleep_for(std::chrono::seconds(1));</code> to sleep for a second. I found that if I adjust the system time backwards during the sleep, the sleep time would extend for the amount of time I just adjusted.</p>
  
  <p>But <code>std::this_thread::sleep_for()</code> is supposed to work regardless of system time unlike <code>std::this_thread::sleep_until()</code>, which probably should exhibit the behavior mentioned above.</p>
  
  <p>When I look at the Visual C++ 2012's implementation of <code>std::this_thread::sleep_for()</code>, I found </p>
  
  <pre><code>template&lt;class _Rep,
  class _Period&gt; inline
  void sleep_for(const chrono::duration&lt;_Rep, _Period&gt;&amp; _Rel_time)
  {   // sleep for duration
  stdext::threads::xtime _Tgt = _To_xtime(_Rel_time);
  sleep_until(&amp;_Tgt);
  }
  </code></pre>
  
  <p>So <code>sleep_for()</code> is implemented using <code>sleep_until()</code> in Visual C++ 2012. I searched the C++11 standard, and it doesn't really forbid this kind of implementation. So how can I get to sleep for a fixed period of time not affected by system clock adjustment?</p>