package Synchronization;

// final so subclassing cannot upset if (...) wait() and notify()
// but notify() (and wait() too) are public methods so still risky
// better to create a hidden object and do notify(), wait() inside it
public final class BinarySemaphore extends Semaphore {

   public BinarySemaphore() {super();}  // constructors

   public BinarySemaphore(int initial) {super((initial!=0) ? 1:0);}

   public BinarySemaphore(boolean initial) {super(initial ? 1:0);}

   public final synchronized void V() {
      super.V();
      if (value > 1) value = 1; // cap the value
   }
}
