Presentation is loading. Please wait.

Presentation is loading. Please wait.

Monitors and Inter-Process Communication

Similar presentations


Presentation on theme: "Monitors and Inter-Process Communication"— Presentation transcript:

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

2 Basic Concept Consists of a lock (a mutex) and zero or more condition variables A queue © 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" © 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 © 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 © 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 © 2004, D. J. Foreman

7 IPC Pipes Message passing anonymous named send() & receive()
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 © 2004, D. J. Foreman

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

9 Condition Variables vs Semaphores
CV's Semaphores Only in monitors Anywhere BUT monitors Wait always blocks Wait 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 © 2004, D. J. Foreman


Download ppt "Monitors and Inter-Process Communication"

Similar presentations


Ads by Google