IT lexicon › Programming › Condition variable

Condition variable

Programming På svenska → Updated: 2026-11-15

A synchronization primitive that allows a thread to sleep until another thread signals that a condition has become true.

Condition variables solve the polling problem: instead of a thread repeatedly checking if a condition is true, it can wait on a condition variable until another thread signals. Typically used with a mutex protecting the condition itself: the thread locks the mutex, checks the condition, and if false, calls wait() (which atomically releases the mutex and blocks until someone calls notify()). When a producer thread modifies the condition and calls notify_all(), all waiters wake and reacquire the lock.

Condition variables originated in 4.2BSD (1983) as sleep/wakeup and were formalized in POSIX (pthread_cond_wait, 1995). They are the foundation of classical concurrent patterns: producer-consumer, reader-writer locks, and barrier synchronization.

← Back to the lexicon