2. Monitors
Semaphore provide convenient and effective mechanism for process synchronization,
using them incorrectly can result in timing errors that difficult to detect.
Suppose process interchange order of wait() and signal()
Signal(mutex)
//critical section
Wait(mutex)
Suppose signal(mutex) eplaced with wait(mutex)
wait(mutex)
//critical section
Wait(mutex)
Produce deadlock
3.
4. Monitors
A monitor is an ADT which has set of programmer defined operations that provide
mutual exclusion within monitor.
Monitors define declaration of variables along with bodies of procedures and
functions that operates on those variables.
Representation of monitor type cannot directly used by the various processes.
Procedure within monitor only access those variables that are declared within
monitor and formal to those functions.
Local variables accede by local procedures only.
7. Monitor ensures that only one process at a time is active within a monitor.
We need to provide additional synchronization mechanisms. And this can be
provided by condition Construct
To implement synchronization programmer needs to define one or more variables
of type
condition x,y;
Wait() and signal() operations are invoked by these variables.
x.wait()
Process invoking this operation is suspended until another process invokes
x.signal();
x.Signal() operation resumes exactly one suspended process.
8. Suppose x.signal() operation invoked by process P there exits a suspended process
Q associated with condition x.
Two possibilities:
1. Signal and wait: P either waits until Q leaves the monitor or wait for another
condition
2. Signal and continue: Q either waits until P leaves the monitor or wait for another
condition