title: Effect of usleep(0) in C++ on Linux
body: <p>The <a href="http://pubs.opengroup.org/onlinepubs/7908799/xsh/usleep.html" rel="noreferrer">documentation for usleep</a> states that calling <code>usleep(0)</code> has no effect. However, on my system (RHEL 5.2) running the small snippets of C++ code below, I find that it actually appears to have the same effect as <code>usleep(1)</code>. Is this to be expected, and if so, why is there the discrepancy between the documentation and what I see in real life?</p>
  
  <p><strong>Exhibit A</strong></p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  
  int main()
  {
      for( int i = 0; i &lt; 10000; i++ )
      {
          usleep(1);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>$ time ./test
  real   0m10.124s
  user   0m0.001s
  sys    0m0.000s
  </code></pre>
  
  <p><strong>Exhibit B</strong></p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  
  int main()
  {
      for( int i = 0; i &lt; 10000; i++ )
      {
          usleep(1);
          usleep(0);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>$ time ./test
  real   0m20.770s
  user   0m0.002s
  sys    0m0.001s
  </code></pre>