title: boost::this_thread::sleep() vs. nanosleep()?
body: <p>I recently came across the need to sleep the current thread for an exact period of time.  I know of two methods of doing so on a POSIX platform: using <code>nanosleep()</code> or using <code>boost::this_thread::sleep()</code>.</p>
  
  <p>Out of curiosity more than anything else, I was wondering what the differences are between the two approaches.  Is there any difference in precision, and is there any reason <em>not</em> to use the Boost approach?</p>
  
  <p><code>nanosleep()</code> approach:</p>
  
  <pre><code>#include &lt;time.h&gt;
  ...
  struct timespec sleepTime;
  struct timespec returnTime;
  sleepTime.tv_sec = 0;
  sleepTime.tv_nsec = 1000;
  nanosleep(&amp;sleepTime, &amp;returnTime);
  </code></pre>
  
  <p>Boost approach:</p>
  
  <pre><code>#include &lt;boost/date_time/posix_time/posix_time.hpp&gt;
  #include &lt;boost/thread/thread.hpp&gt; 
  ...
  boost::this_thread::sleep(boost::posix_time::nanoseconds(1000));
  </code></pre>