title: Inter-Process synchronization with mutex and semaphore
body: <p>I am doing self-studying of operating systems. Tanenbaum in  his book modern operating systems states an example where he explains how three semaphores (one of which is a mutex) coordinate a producer-comsumer process pair. I am having little trouble grasping it. Can anyone please explain how it is being achieved. Any help will be appreciated. Thanks.</p>
  
  <pre><code>    #define N 1 00
      typedef int semaphore;
      semaphore mutex = 1 ;
      semaphore empty = N;
      semaphore full = 0;
      void producer(void)
      {
  
      int item;
      while (TRUE) {
      item = produce_item( );
      down( &amp;empty);
      down( &amp;mutex);
      inserUtem(item);
      up(&amp;mutex);
      up(&amp;full);
  }
  
      void consumer(void)
      {
  
      int item;
      while (TRUE) {
      down(&amp;full);
      down( &amp;mutex);
      item = remove_ item( );
      up(&amp;mutex);
      up(&amp;empty);
      consume_item(item);
  
  }
  </code></pre>