title: Semaphore wait() and signal()
body: <p>I am going through process synchronization, and facing difficulty in understanding semaphore. So here is my doubt:</p>
  
  <p>the source says that</p>
  
  <p>" Semaphore S is an integer variable that is accessed through standard <strong>atomic</strong> operations i.e. wait() and signal().</p>
  
  <p>It also provided basic definition of wait() </p>
  
  <pre><code>wait(Semaphore S)
  {
     while S&lt;=0
       ; //no operation
     S--;
  }
  </code></pre>
  
  <p>Definition of signal()</p>
  
  <pre><code>signal(S)
  {
     S++;
  }
  </code></pre>
  
  <p>Let the initial value of a semaphore be 1, and say there are two concurrent processes P0 and P1 which are not supposed to perform operations of their critical section simultaneously.</p>
  
  <p>Now say P0 is in its critical section, so the Semaphore S must have value 0, now say P1 wants to enter its critical section so it executes wait(), and in wait() it continuously loops, now to exit from the loop the semaphore value must be incremented, but it may not be possible because according the source, wait() is an atomic operation and can't be interrupted and thus the process P0 can't call signal() in a single processor system.</p>
  
  <p>I want to know, is the understanding i have so far is correct or not. and if correct then how come process P0 call signal() when process P1 is strucked in while loop?</p>