liveBook · Manning

Condition variable

A condition variable is a synchronization object that allows threads to wait for a shared-state condition and be notified when it may have changed.

How 7 Manning books explain it

Learn Concurrent Programming with Go

A condition variable is a synchronization mechanism that allows threads or goroutines to wait for a specified condition and be notified when it may hold.

How it is used
Coordinates goroutines that must wait for protected shared state to satisfy a condition without timed polling.
How deep it goes
Works through Wait, Signal, Broadcast, missed notifications, multi-waiter coordination, and implementations of readers–writer locks and waitgroups.
Examples
Uses a bank balance, a multiplayer game lobby, writer starvation, and a custom waitgroup.
What you can do after
Build it from scratch as a waitgroup or write-preferring readers–writer lock using a mutex, predicates, waits, and broadcasts.

Read how Learn Concurrent Programming with Go explains condition variable →

Modern C, Third Edition

A condition variable is a thread-synchronization object that allows threads to wait until a shared-state condition may have become true.

How it is used
Models processing dependencies so threads wait for changes in shared state before doing their assigned work.
How deep it goes
Works through guarded wait loops, timed returns, signaling, and mutex synchronization; treats full liveness verification as a separate challenge.
Examples
Uses accounting, update, and draw threads with separate condition variables and shared iteration, completion, and drawing state.
What you can do after
Apply it via the C threads API by guarding waits with shared-state tests and rechecking those tests after return.

Read how Modern C, Third Edition explains condition variable →

C++ Concurrency in Action, Second Edition

A condition variable is a synchronization primitive that lets threads wait for a condition and be notified when it may have changed.

How it is used
Lets threads wait for work or another condition instead of periodically checking shared data.
How deep it goes
Works through mutex-protected queue operations and a thread-safe queue abstraction, without describing implementation internals.
Examples
Uses a producer–consumer data queue and a thread-safe queue with push() and wait_and_pop().
What you can do after
Build it from scratch by pairing a mutex-protected queue predicate with wait() and notify_one().

Read how C++ Concurrency in Action, Second Edition explains condition variable →

Object-Oriented Software Design in C++

A condition variable is a synchronization primitive on which threads wait for a condition and from which they can be notified when that condition may have changed.

How it is used
Synchronizes producer and consumer threads around full and empty states of a shared queue.
How deep it goes
Explains unique_lock, wait, notification, condition rechecking, and queue coordination, while deferring broader multithreading complexity.
Examples
Uses a bounded SharedQueue with multiple producers, multiple consumers, capacity checks, notifications, and threaded output.
What you can do after
Build it from scratch using C++ condition_variable, unique_lock, mutexes, wait loops, and notifications.

Read how Object-Oriented Software Design in C++ explains condition variable →

Software Design for Python Programmers

A condition object is a synchronization object that lets threads wait for a predicate on shared state and be notified when that predicate may have changed.

How it is used
Coordinates producer–consumer access to a bounded shared queue when mutexes and semaphores alone are insufficient.
How deep it goes
Explains acquisition, predicate loops, release during waiting, reacquisition, rechecking, critical regions, and notification.
Examples
Uses a Python bounded queue with multiple producers, multiple consumers, capacity limits, notifications, and zero-value end sentinels.
What you can do after
Apply it via Python's threading.Condition to coordinate protected access and waiting threads around shared-state predicates.

Read how Software Design for Python Programmers explains condition variable →

100 Go Mistakes and How to Avoid Them

A condition variable is a synchronization object that allows concurrent executions to wait for and announce the occurrence of a condition.

How it is used
Coordinates multiple goroutines waiting for shared state changes without combining the solution with a more complex WaitGroup.
How deep it goes
Defines the rendezvous model and traces Wait through unlocking, suspension, notification, and relocking.
Examples
Uses donation listeners, balance thresholds, mutex-protected updates, and Broadcast notifications to demonstrate synchronization.
What you can do after
Apply it via sync.Cond to coordinate listeners around a mutex-protected condition and broadcast state changes safely.

Read how 100 Go Mistakes and How to Avoid Them explains condition variable →

Modern C

A condition variable is a synchronization object on which threads wait for a predicate involving shared state to become true.

How it is used
Coordinates conditional processing dependencies between threads that share protected state.
How deep it goes
Explains mutex association, timed and untimed waits, predicate loops, early returns, signaling, initialization, and destruction.
Examples
Uses accounting, updating, and drawing threads whose iteration, completion, and input predicates govern calls to cnd_t waits.
What you can do after
Apply condition variables through cnd_t waits, mutex-protected predicates, repeated checks, and targeted signals.

Read how Modern C explains condition variable →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.