liveBook · Manning

Condition variable

As explained in Modern C

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

A condition variable is a synchronization object that lets a thread wait until shared state may satisfy a predicate. It accompanies a mutex: lock the mutex, test the predicate, and wait while the predicate remains false. TAKEAWAY: returning from a wait does not prove that the predicate is true; check it again. section 18.5

Coordinating game threads

An accounting thread waits while L->accounted == L->iteration; an update thread waits while L->accounted < L->iteration; and a drawing thread waits while no new iteration or input change exists. Each uses its own condition variable—acco, upda, or draw—while sharing L->mtx. The update thread signals acco and draw after advancing the iteration.

How Modern C covers it

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 it assumes
Assumes shared state, mutexes, critical sections, and threads while emphasizing predicate checks and termination conditions.
What you can do after
Apply condition variables through cnd_t waits, mutex-protected predicates, repeated checks, and targeted signals.
How it connects
Connects condition variables to mutexes, shared state, predicates, critical sections, thread coordination, and atomic data.

Also explained in

Compare how 7 books explain condition variable →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.