title: Does mutex and semaphores "Busy wait" in a LINUX systems?
body: <p>Recently I came to know that <strong>Sleep</strong> system call in a linux kernel will suspend the current calling thread to a <strong>suspended/blocked</strong> state, meaning they wont utilise the CPU until the mentioned time elapse. - <em>perfectly understood</em>.</p>
  
  <p>Now coming to mutex and semaphores,</p>
  
  <p>Mutex Locks:</p>
  
  <pre><code>acquire() {
  while (!available)
  ; // busy wait    --&gt; my doubt
  available = false;;
  }
  
  release() {
  available = true;
  }
  </code></pre>
  
  <p>Semaphore locks:</p>
  
  <pre><code>wait(S) {
  while (S &lt;= 0)
  ; // busy wait --&gt; my doubt
  S--;
  }
  signal(S) {
  S++;
  }
  </code></pre>
  
  <p>P.S: these code snippets are taken from <em>"operating systems concepts -9th edition"</em> by ABRAHAM SILBERSCHATZ</p>
  
  <p><strong>My question:</strong></p>
  
  <p>I know that busy wait is not an efficient way to approach synchronisation problems, but from the code snippets mentioned above i got a doubt that  using mutex and semaphores will end up in a <strong>busy wait</strong> ?? (<em>though mutexes and semaphores being widely used to solve most sysnc problems</em>). </p>
  
  <p><strong>Which inturn make me feel that using mutex &amp; semaphores is not an efficient way to solve sync problems as it is going to consume CPU cycles</strong> <em>(because it will not lead to suspended state rather spinning in a while loop )</em>.</p>
  
  <p><em>To be short :</em> <strong>Does mutexes and semaphores busy waits rather putting the waiting thread thread to a suspended state ??</strong> </p>
  
  <p>Thanks in advance !!. Kindly correct me if am wrong in my understanding !!</p>