Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.

Similar presentations


Presentation on theme: "© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication."— Presentation transcript:

1 © 2004, D. J. Foreman 1 Monitors and Inter-Process Communication

2 © 2004, D. J. Foreman 2 Basic Concept  Consists of a lock and zero or more condition variables  A queue

3 © 2004, D. J. Foreman 3 Monitors  Look like C++ "classes" ■ encapsulation ■ private mutex (semaphore) variable ■ public interfaces  public interfaces use P, V for protection ■ acts like a "critical section"

4 © 2004, D. J. Foreman 4 Condition Variables (cv's)  Private to monitor  Access via: ■ wait() – suspends process ■ signal() – lets ONE process resume ■ queue() – TRUE if #waiters on cv > 0  2 approaches ■ Hoare – p1 waiting, p0 signals, p1 starts now ■ Mesa (Hansen) – p1 waiting, p0 signals and continues to run, p1 re-checks when p0 ends fewer context switches

5 © 2004, D. J. Foreman 5 Comparison  Hoare semantics if (R is held) R.wait(); //proceed  Mesa semantics while (R held) R.wait(); // forces re-try //proceed

6 © 2004, D. J. Foreman 6 Mesa vs. Hoare  Hoare: signaler releases lock, waking thread acquires and runs  Mesa: signaler keeps lock, waking thread must wait on acquire

7 © 2004, D. J. Foreman 7 IPC  Pipes ■ anonymous limited to parent-child due to file reference child inherits pipe-end as an open file ■ named pipe is opened with a name names are system-wide managed like files  Message passing ■ send() & receive() ■ synchronous & asynchronous

8 © 2004, D. J. Foreman 8 Notes on Java  The JVM ■ uses monitors for mutual exclusion ■ provides wait and notify for cooperation

9 © 2004, D. J. Foreman 9 Condition Variables vs Semaphores CV'sSemaphores Only in monitorsAnywhere BUT monitors Wait always blocksWait blocks if count>0 Signal releases a blocked thread or does nothing Signal releases a blocked thread or increments count Either caller or released thread continues (Hoare vs Mesa) Both continue


Download ppt "© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication."

Similar presentations


Ads by Google