/**
 * Worker.java
 *
 * This thread is used to demonstrate the operation of a semaphore.
 *
 * @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 Worker extends Thread
{
   public Worker(Semaphore s, String n) {
	name = n;
      sem = s;
   }

   public void run() {
      while (true) {
         sem.P();

         System.out.println(name + " is in critical section.");

         Runner.criticalSection();

         sem.V();

         System.out.println(name + " is out of critical section.");

         Runner.nonCriticalSection();
      }
   }

   private Semaphore sem;
  private String name;
}


