liveBook · Manning

Cnd_t

As explained in Modern C

cnd_t is the C standard threads type representing a condition variable used for thread waiting and notification.

Waiting until work is available

A worker locks a mutex, checks its shared-state condition, and waits when no work exists: `mtx_lock(&L->mtx); while (!L->finished && (L->accounted == L->iteration)) life_wait(&L->acco, &L->mtx); life_account(L); cnd_signal(&L->upda); mtx_unlock(&L->mtx);`. Here, `L->acco` is a cnd_t condition variable identifying the accounting condition; the Boolean expression remains the condition that must be checked. section 18.5

cnd_t is the C standard threads type for coordinating conditional dependencies between threads. A condition variable gives a thread a place to wait until another thread signals that shared state may have changed; it does not store the condition expression itself. section 18.7 section 18.5

Always place a wait inside a loop that checks the predicate again after return. A wait can return because of a timeout or before the condition expression has changed; blocking on cnd_t or mtx_t also frees processing resources. section 18.5 section 18.6

How Modern C covers it

How deep it goes
Defines waiting, signaling, initialization, and predicate-loop discipline, but does not detail implementation internals.
Examples
Uses accounting, update, and draw threads waiting on separate condition variables in a shared Life simulation.
What it assumes
Assumes mutexes, threads, shared state, and critical sections while distinguishing predicates from condition-variable objects.
What you can do after
Apply it via the C standard threads API to block workers, signal dependent work, and recheck shared-state predicates safely.
How it connects
Ties condition variables to mutexes, threads, shared state, timed waits, and critical sections.

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.