Tags:
create new tag
view all tags
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();
        }
    }
}

-- AntonioValletta - 15 Nov 2001
Topic revision: r1 - 2001-11-15 - AntonioValletta






 
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback