You are on page 1of 1

public class Semaphore {

int n;
String name;
public Semaphore (int max, String S) {
this.n=max;
this.name=S;
}

public synchronized void P(Semaphore A) {


n--;
if(n<0) {
try {
A.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}

}
public synchronized void V(Semaphore A) {
n++;
if (n<=0)
A.notify();

}
}

You might also like