CS 3733 Operating Systems
Lecture 21 [11/5/97]: Monitors and Message Passing
Reading: Tanenbaum 2.2.8 and 2.2.9
- Monitors:
- Monitors were developed in the 1970's to make it easier to
avoid deadlocks. They fit well in an object-oriented paradigm.
- A collection of precedures, variables, and data structures grouped together.
- Processes can call the monitor procedures but cannot access the
internal data structures.
- Only one process at a time may be be active in a monitor.
- A monitor is a language construct.
- Compiler usually enforces mutual exclusion.
- Monitor condition variables allow for blocking and unblocking. The operations are:
monitor_wait
and monitor_signal
. Since the monitor
assures mutual exclusion, they are used without a mutex lock.
- Monitor operations:
-
monitor_wait(V)
blocks a process.
-
monitor_signal(V)
unblocks a process waiting for the condition variable
V
.
-
monitor_signal
causes a new process to enter the monitor, replacing the
original.
- Alternatively, it could be required that
monitor_signal
be the last
statement in a monitor routine.
- If a condition variable is signaled with nobody waiting, the signal is lost.
- Figure 2-14, page 48 of Tanenbaum shows a solution to the producer-consumer using monitors.
-
count
is only modified inside the monitor so it is protected.
-
enter_item
and remove_item
can be ordinary procedures as they
are called only inside the monitor.
- condition variables do not have values --- better to think of them as part
of an object.
- One modern language that supports monitors is Java.
- When declaring a method in Java, the keyword
synchronized
is used to indicate that the method is part of a monitor.
- There is one monitor per class.
- Java also has condition variables.
- Message passing systems
- Can be used across networks.
- Messages can be lost.
- Usually has some sort of handshaking such as an acknowledgement.
- Must have a way of identifying sender and receiver.
- Must have a way of authenticating a message.
- Messages that are not yet read must be buffered by the operating system
or must go to a mailbox.
- If no buffering get the rendezvous mechanism.
- A pipe is a buffering mechanism that doesn't preserve message boundaries.
Revision Date: 11/4/97