title: Block a thread with sleep vs block without sleep
body: <p>I've created a multi-threaded application using C++ and POSIX threads. In which I should now block a thread (main thread) until a boolean flag is set (becomes true).</p>
  
  <p>I've found two ways to get this done.</p>
  
  <ul>
  <li><p>Spinning through a loop <em>without</em> sleep.</p>
  
  <pre><code>while(!flag);
  </code></pre></li>
  <li><p>Spinning through a loop <em>with</em> sleep.</p>
  
  <pre><code>while(!flag){
       sleep(some_int);
  }
  </code></pre></li>
  </ul>
  
  <p>If I should follow the first way, why do some people write codes following the second way? If the second way should be used, why should we make current thread to sleep? And what are disadvantages of this way?</p>