title: Bounded-buffer using java library semaphore
body: <p>i currently have an assignment where i'm supposed to make a semaphore for the bounded buffer problem. I think my first code is ok and should work (if i understand semaphores right, which i'm not sure about btw)</p>
  
  <p>The second part of the assigment is to use java library to implement semaphores. Have i done this right? 
  I have provided both code blocks for each part of the assignment. i just need a verification if my code is correct and maybe some input about the use of java semaphore library :)   </p>
  
  <pre><code>semaphore mutex = 1;
  semaphore fillCount = 0;
  semaphore emptyCount = BUFFER_SIZE;
  
  procedure producer() {
    while (true) {
      item = produceItem();       
      down(emptyCount);       
          down(mutex);            
              putItemIntoBuffer(item);    
          up(mutex);          
      up(fillCount);      
  }
  }
  
  procedure consumer() {
  while (true) {
      down(fillCount);                
          down(mutex);                
              item = removeItemFromBuffer();  
          up(mutex);              
      up(emptyCount);             
      consumeItem(item);      
  }
  }
  </code></pre>
  
  <p>With Java-Semaphore:</p>
  
  <pre><code> Semaphore semaphore = new Semaphore(1);
  
  public producer(){     
  
  semaphore.acquire();  
      putItemIntoBuffer(item);  
  semaphore.release(); 
  
  }
  
  public consumer(){
  semaphore.acquire();
  
  removeItemFromBuffer(item);   
  
  semaphore.release();
   }
  </code></pre>