title: What does mutex and semaphore actually do?
body: <p>I want some clarification regarding mutex and semaphore.<br>
  My question is,      </p>
  
  <ol>
  <li>What mutex actually do when a thread tries to enter a region locked by a mutex,
  a. it waits for the lock to be released? 
  or b. it goes to sleep until the lock is released. In that case how it is wake up again when the lock is released?</li>
  <li>Same question as 1, but in this case it is semaphore.</li>
  <li>Can you give me some code regarding busy waiting in pthread in C, and also a case where thread goes to sleep instead of waiting? does sleep mean it is blocked or sleeping is another kind of busy waiting?</li>
  <li>i want to know some programs where this situations are covered, for example some c source codes where busy waiting, blocking etc are implemented.</li>
  </ol>