title: Semaphore Vs Mutex
body: <p>I was reading a bit of Mutex and semaphore. </p>
  
  <p>I have piece of code</p>
  
  <pre><code>int func()
  {
   i++;
   return i;
  }
  </code></pre>
  
  <p>i is declared somewhere outside as a global variable.
  If i create counting semaphore with count as 3 won't it have a race condition? does that mean i should be using a binary semaphore or a Mutex in this case ?</p>
  
  <p>Can somebody give me some practical senarios where Mutex, critical section and semaphores can be used.</p>
  
  <p>probably i read lot. At the end i am a bit confused now. Can somebody clear the thought.</p>
  
  <p>P.S: I have understood that primary diff between mutex and binary semaphore is the ownership. and counting semaphore should be used as a Signaling mechanism.</p>