Realizzare la versione "Mediator" del tipo di dato Monitor
utilizzando un monitor di tipo "Gladiator".
class Mediator {
/* Implements Hoare-like Delay and Continue primitives
using Java's wait() and notify(), which provide a kind
of monitor where the "continuer" has priority over the
"continuee" */
boolean urgent = false;
int waiting = 0;
public synchronized void mDelay ()
throws InterruptedException {
waiting = waiting + 1;
while (!urgent) wait();
urgent = false;
notifyAll();
}
public synchronized void mContinue ()
throws InterruptedException {
if (waiting != 0) {
waiting = waiting - 1;
while (urgent) wait();
urgent = true;
notifyAll();
wait();
}
}
}
</pre>
-- Users.AntonioValletta - 15 Nov 2001
This topic: Sistemioperativi1
> SoluzioneMediator9Febbraio2000
Topic revision: r1 - 2001-11-15 - AntonioValletta