operating-systems concurrency

Definition

Condition Variable

A condition variable is a synchronisation primitive used within a monitor to allow processes to wait for a specific condition to become true. Unlike semaphores, condition variables have no internal counter; they are purely for signalling.

Operations:

  • cwait(c): Suspends the calling process on condition variable , yielding the monitor’s mutual exclusion.
  • csignal(c): Resumes one waiting process. If no processes wait, the signal has no effect (unlike a semaphore’s operation, which is remembered).

Signalling Semantics

When csignal resumes a waiting process, different implementations define who controls the monitor:

Hoare Semantics (Signal-and-Wait)

The signaler is suspended immediately; the resumed process enters the monitor and executes.

Mesa Semantics (Signal-and-Continue)

The signaler continues execution; the resumed process waits until the monitor is free, then must re-check the condition (it may no longer hold).