liveBook · Manning

Cnd_broadcast

As explained in Modern C

cnd_broadcast is a C11 condition-variable function that wakes all threads waiting on a condition variable.

Wake every waiter

After shared state makes a condition true, call cnd_broadcast(&condition); every thread waiting on that condition variable wakes and returns from cnd_wait or cnd_timedwait. Each waiter must reacquire the mutex and check its condition again. section 18.5

TAKEAWAY: cnd_broadcast wakes all threads waiting for the corresponding condition variable; it does not establish that every thread's predicate is now satisfied. section 18.5

Use the operation with these rules:

  • Pair waiting with a mutex held by the calling thread; waiting temporarily releases it and reacquires it before returning. section 18.5
  • Keep each wait inside a loop that tests the condition, because a wait can return early. section 18.5

How Modern C covers it

How deep it goes
Defines wakeup behavior and mutex discipline, while deferring implementation internals.
Examples
Uses input, account, update, and draw threads with predicate-checking wait loops.
What it assumes
Assumes mutexes, condition predicates, and waiting interfaces; emphasizes rechecking predicates after wakeup.
What you can do after
Apply it via the C11 condition-variable API while protecting shared state with the associated mutex.
How it connects
Connects condition variables with mutexes, cnd_wait, cnd_timedwait, and cnd_signal.

Also explained in

Compare how 2 books explain cnd_broadcast →

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.