signal operation on a condition variable.
To illustrate this concept,
say there are two threads, named Thread1 and Thread2.
Thread1 acquires access to the monitor first and then executes a
wait operation on some condition variable, causing it to be put on a wait
queue. Now Thread2 can acquire the monitor, and it performs a
signal operation on the condition variable.
Now there are two choices as to how execution can proceed with only one thread active in the monitor. If Mesa semantics are implemented, Thread2 will finish executing, and then Thread1 will be allowed to reacquire the monitor. Note that there is no guarantee that the condition Thread1 was waiting on will still hold by the time it reacquires the monitor.
Another option is
Hoare semantics where Thread2 is put
on a signal queue after executing the signal
operation on the condition
variable. Thread1 is then given access to the monitor automatically
and allowed to finish. Once it has finished Thread2 is given control
again and allowed to finish. Thus we can see that the results of Hoare
monitors are more predictable because control of the monitor is being
passed explicitly from one thread to the next.
Following the links above will run applets that illustrate the above protocols.
.java files associated with this applet.
The AnimThread class in the AnimThread.java file is an
extension of the java.lang.Thread class. These AnimThreads
are basically threads with coordinates and methods to change those
coordinates during animation.
The Mesa and Hoare classes, in the
Mesa.java and
Hoare.java files respectively, include all the code for
the different monitors. In these applets green is used to denote a
running thread, red denotes a waiting thread, and yellow denotes a
signalling thread in the Hoare monitor.