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_;
}
}