title: Does sleep/nanosleep work by utilizing a busy wait scheme?
body: <p>I am wondering how is sleep/nanosleep internally implemented? Consider this code:</p>
  
  <pre><code>{ // on a thread other than main() thread
    while(1)
    {
      //do something
      sleep(1);
    }
  }
  </code></pre>
  
  <p>would the CPU be doing constant context switching to check if sleep of 1 sec is done (i.e. an internal busy wait).</p>
  
  <p>I doubt it works this way, too much inefficiency. But then how does it work?</p>
  
  <p>Same question applies to nanosleep.</p>
  
  <p>Note: If this is implementation/OS specific, then how can I possibly implement a more efficient scheme that doesn't lead to a constant context switching?</p>