class Semaphore

class Semaphore

class Semaphore {

private int value_;

Semaphore (int initial) { value_ = initial; }

synchronized public void up() {

++value_;

notify(); // [value>0]

}

synchronized public void down() {

while (value_== 0) {

try {wait();} catch (InterruptedException e){}

}

--value_;

}

}

Previous slide Next slide Back to the first slide View Graphic Version