Course Material
Monitor slides used in class is available in the
common directory
with filename
10-Monitors.pdf.
Many systems provide mutex locks and condition variables in an
unstructured way.
We can simulate a monitor with mutex locks and condition variables.
Read the Mutex and condition variables section of
Solaris Multithreaded Programming
to learn how this is done.
This is required reading!
Study
Multithreaded Programming with
ThreadMentor: A Tutorial
If you wish to print
these slides, print them double-sided and print as many slides as
possible on the same page. Let us save a tree!
Programming Material
Do
Programming Assignment V.
Homework Assignment
Do the following problems
(Most are for THIS week):
for (i = 0; i < n; i++)
CV.Signal();
This method uses a single thread, which is executing
in a monitor, to release threads waiting on condition
variable CV,
where n
is sufficiently large so that all blocked threads
are released.
The second method just releases one thread, and allows the released thread to release other threads. This is referred to as cascading signals.
Analyze and compare these methods under Hoare type and Mesa type monitors.// place where threads block CV.Wait(); CV.Signal(); // this one is released and release the next one // other work in a monitor CV.Signal(); // initialize a cascading release here
monitor deadlock
condition p, q;
void stop(void)
{
p.wait;
......
q.signal;
}
void go(void);
{
......
p.signal;
q.wait;
}
// no initialization is required
}
Suppose we have processes P1 and
P2 as follows:
The intention of this monitor is that P1 is required to wait on condition p until P2 has completed some task, at which point it calls deadlock.go to release P1. P2 then waits until P1 has performed its task, when it signals condition q to indicate that P2 may continue.P1: repeat ..... deadlock.stop; ..... until false; P2: repeat ..... deadlock.go; ..... until false;
This program looks correct and seems can perform the indicated task. But, it has the potential to deadlock. Find this deadlock. Would the deadlock still be there is the monitor is a Mesa type?
| We do not collect your practice work; but, similar problems will appear in quizzes and exams in the future. Note that I will not make any announcement in class for these short quizzes. In other word, short quizzes may take place at any time as long as I see it is appropriate. |