A seguir: Exclusão Mútua com Semáforos Acima: Sincronização com Memória Compartilhada Anterior: Semáforos
public class Semaphore {
int value;
public Semaphore(int initialValue){
value = initialValue;
}
public synchronized void P() {
while (value <= 0 ) {
try {
wait();
catch(InterruptedException e){}
}
value--;
}
public synchronized void V() {
p++;
notify();
}
}