- - - - CENAPAD-MGCO

contents index A seguir: Propriedades do Buffer Compartilhado Acima: Modelos Formais para Programas Anterior: Motivação


O Buffer Compartilhado

Código Java Simplificado
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();
  }
}



 

Osvaldo Carvalho - Postscript - Comentários?