Mesa semantics

Source: adapted from Andrew Birrell technical note.

A condition variable c is associated with a specific lock m. Calling c.Wait() enqueues the current thread on c (suspending its execution) and unlocks m, as a single atomic action. When this thread resumes execution it re-locks m.

c.Signal() examines c, and if there is at least one thread enqueued on c then one such thread is dequeued and allowed to resume execution; this entire operation is a single atomic action.

c.Broadcast() examines c and if there are any threads enqueued on c then all such threads are allowed to resume execution. Again, this entire operation is a single atomic action: the threads to be awoken are exactly those that had called c.Wait() before this call of c.Broadcast(). Of course, the awoken threads have to wait in line to acquire the lock m.

Note that these are the Mesa (and Modula, PThreads, Java and C#) semantics. Tony Hoare's original condition variable design had the Signal operation transfer the lock to the thread being awoken and had no Broadcast.