parallele-programmierung/u05-4/Semaphore.java

19 lines
295 B
Java

class Semaphore {
private int value;
public Semaphore(int value) {
this.value = value;
}
synchronized public void acquire() throws InterruptedException {
while (this.value <= 0) {
wait();
}
this.value--;
}
synchronized public void release() {
this.value++;
notify();
}
}