public class Semaphore { public Semaphore (int initialValue) { ; } // initialize a sempahore with value zero public Semaphore () { this(0); } public void down () { // TODO: Implement this! } public void up () { // TODO: Implement this! } public static void main (String [] args) { // Semaphore test functionality final Semaphore semaphore = new Semaphore(1); for (int i=0;i < 4; i++) { final int threadID = i; Thread t = new Thread (new Runnable() { public void run() { System.out.println("[Thread " + threadID + "] downing the semaphore"); semaphore.down(); System.out.println("[Thread " + threadID + "] going to sleep"); try { Thread.sleep(1000); // wait for 1 second } catch (InterruptedException iesx) {} // ignored System.out.println("[Thread " + threadID + "] upping the semaphore"); semaphore.up(); } }); t.start(); } } }