-
-
-
CENAPAD-MGCO
A seguir: Propriedades do Buffer Compartilhado
Acima: Modelos Formais para Programas
Anterior: Motivação
class Buffer {
private Queue buffer;
int n;
final int MAX = 10;
public Buffer() {
buffer = new Queue(MAX); n = 0;
}
public synchronized void put(char x) {
while(n >= MAX) {
wait();
}
buffer.append(x); n++;
notify();
}
public synchronized char get() {
while (n <= 0){
wait();
}
notify(); n--;
return buffer.dequeue();
}
}