1. A discussion on the recent assignment
2. Implementation of Monitors
Implementation for procedure
entries:
use one semaphore (mutex) per monitor
P (mutex) ;
to ensure mutual exclusion of procedure
entries
.. procedure body ..
if (s_count > 0) V (s) ;
to wake up a procedure that signalled
some other process and
blocked
s_count specifies the number of such blocking processes
else V (mutex)
and do not release mutex if you
are waking up another procedure,
since that means transfer of mutex
Implementation for condition variables:
use one semaphore for each condition
variable,
and a counter that indicates the
number of procedures
waiting on that variable.
Let's take a case of a condition variable c
Implementing c.wait
c_count = c_count + 1;
one more procedure is waiting on
c
if (s_count >0) V (s);
just before you sleep, wakeup a
procedure that is waiting after a signal
(here you don't need to release
mutex)
else V(mutex);
if there is none, then release
the mutex
P(c);
now wait on the condition variable
c_count = count - 1;
you are no more waiting
Implementing c.signal
if (c_count > 0) {
some one is waiting on c
s_count = s_count
+1;
just before you signal, increment
the count of procedures
waiting after a signal waiting
after signal
V(c);
signal
one procedure waiting on c
P(s);
now wait as a process that sent a signal
s_count = s_count
- 1;
you are no more waiting
}