/** * P.308 * Semaphore.java * * A basic counting semaphore using Java synchronization. */ public class Semaphore { private int s; public Semaphore(int value) { this.s = value; } public synchronized void P() { while (s == 0) { try { wait(); } catch (InterruptedException e) { } } s --; } public synchronized void V() { ++s; notify(); } }