//@author: j.n.magee 11/11/96 //adapted by mh, 02/04/03 /********************************************************/ // // The Semaphore Class // up() is the V operation // down() is the P operation // public class Semaphore { private int value; public Semaphore (int initial) { if (initial<0) { System.exit(1); // out of range error } else { value = initial; } // if } // Semaphore synchronized public void up() { ++value; notify(); // notifyAll() ? } // up synchronized public void down() { try { while (value==0) { wait(); } // end while --value; } catch(InterruptedException e){} } // down } // class Semaphore