/**
 * FirstSemaphore.java
 *
 * This program uses a semaphore as a means of handling synchronization.
 * It creates 5 threads and a thread can perform its critical section
 * only if it is able to complete a P() operation on the sempahore.
 *
 * @author Greg Gagne, Peter Galvin, Avi Silberschatz
 * @version 1.0 - July 15, 1999
 * Copyright 2000 by Greg Gagne, Peter Galvin, Avi Silberschatz
 * Applied Operating Systems Concepts - John Wiley and Sons, Inc.
 */

public class FirstSemaphore
{
   public static void main(String args[]) {
      Semaphore sem = new Semaphore(1);
      
      Worker[] bees = new Worker[5];
      
      for (int i = 0; i < 5; i++)
         bees[i] = new Worker(sem, "Worker " + (new Integer(i)).toString() );
         
      for (int i = 0; i < 5; i++)
         bees[i].start();
   }
}
   

