- - - - CENAPAD-MGCO

contents index A seguir: Imposição de Políticas de Acima: Propriedades de programas paralelos Anterior: Leitores e Escritores: Solução


TicketQueue

int ticket = 0;
OrderedQueue q; // fila ordenada com operacoes put, top e pop

int getTicket() {
  q.put(++ticket);
  return ticket;
}

boolean isTheBest(int ticket) {
  if (q.top() != null){
    return ticket == q.top();
  }
  return true;
}

void ok(int ticket) {
  if (ticket != q.pop()) { //pop() devolve o melhor e o retira da lista
    ERRO!;
  }
}



Osvaldo Carvalho - Postscript - Comentários?