title: Show how counting semaphores can be implemented using only binary semaphores and ordinary machine instructions?
body: <p>I am studying for a midterm and this was one of the practice questions: Show how counting semaphores (i.e, semaphores that can hold an arbitrary value) can be implemented using only binary semaphores and ordinary machine instructions?</p>
  
  <p>I'm not even sure where so start. I found this online;</p>
  
  <pre><code>P(s) { Pb(mutex_s); s = s-1; if(s &lt; 0) {Vb(mutex_s); Pb(delay_s);} Vb(mutex_s); }
  V(s) { Pb(mutex_s); s = s+1; if(s &lt;= 0) Vb(delay_s); else Vb(mutex_s); }
  </code></pre>
  
  <p>Unfortunately, I don't really understand what the answer is telling me.  Can anyone explain this answer to me, or show me in pseudo code how to answer?</p>