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 do not have an internal counter; they are purely used for signaling.
Condition variables provide two primary operations:
cwaitandcsignal.
Operations
- cwait(c): Suspends the execution of the calling process on the condition variable . The process yields the monitor’s mutual exclusion, allowing another process to enter.
- csignal(c): Resumes one process that was suspended on . If no processes are waiting, the signal has no effect (unlike a semaphore’s operation, which is “remembered”).
Signaling Semantics
When a csignal occurs and a waiting process is resumed, there are different semantics for who gets control of the monitor:
- Hoare Semantics (Signal-and-Wait): The signaler process is suspended, and the resumed process immediately takes control.
- Mesa Semantics (Signal-and-Continue): The signaler continues to execute, and the resumed process will enter when the monitor becomes free.