queue. protected Mutex internalMutex; // (Really another Semaphore. Protects "numWaiters".) } When a signal happens on a condition variable that at least one other thread is waiting on, there are at least two threads that could then occupy the monitor: the thread that signals and any one of the threads that is waiting. In order that at most one thread occupies the monitor at each time, a choice must be made. Two schools of thought exist on how best to resolve this choice. This leads to two kinds of condition variables which will be examined next: Blocking condition variables give priority to a signaled thread. Nonblocking condition variables give priority to the signaling thread. Blocking condition variables The original proposals by C. A. R. Hoare and Per Brinch Hansen were for blocking condition variables. With a blocking condition variable, the signaling thread must wait outside the monitor (at least) until the signaled thread relinquishes occupancy of the monitor by either returning or by again waiting on a condition variable. Monitors using blocking condition variables are often called Hoare-style monitors or signal-and-urgent-wait monitors. We assume there are two queues of threads associated with each monitor object e is the entrance queue s is a queue of threads that have signaled. In addition we assume that for each condition variable , there is a queue .q, which is a queue for threads waiting on condition variable All queues are typically guaranteed to be fair and, in some implementations, may be guaranteed to be first in first out. The implementation of each operation is as follows. (We assume that each operation runs in mutual exclusion to the others; thus restarted threads do not begin executing until the operation is complete.) enter the monitor: enter the method if the monitor is locked add this thread to e block this thread else lock the monitor leave the monitor: schedule return from the method wait : add this thread to .q schedule block this thread signal : if there is a thread waiting on .q select and remove one such thread t from .q (t is called "the signaled thread") add this thread to s restart t (so t will occupy the monitor next) block this thread schedule: if there is a thread on s select and remove one thread from s and restart it (this thread will occupy the monitor next) else if there is