/**
 * MutualExclusion.java
 *
 * This abstract class is to be implmented by each solution 
 * to the critical section problem.
 *
 * @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 abstract class MutualExclusion
{
   /**
    * critical and non-critical sections are simulated by sleeping
    * for a random amount of time between 0 and 3 seconds.
    */
   public static void criticalSection() {
      try {
            Thread.sleep( (int) (Math.random() * 3000) );
      }
      catch (InterruptedException e) { }
   }
   
   public static void nonCriticalSection() {
      try {
            Thread.sleep( (int) (Math.random() * 3000) );
      }
      catch (InterruptedException e) { }
   }

   public abstract void enteringCriticalSection(int t);

   public abstract void leavingCriticalSection(int t);

   public static final int TURN_0 = 0;
   public static final int TURN_1 = 1;
}

