liveBook · Manning

Cnd_signal

As explained in Modern C, Third Edition

cnd_signal is a C threads-library function that wakes one thread waiting on a condition variable.

cnd_signal wakes one thread waiting on a condition variable, allowing that thread to return from cnd_wait or cnd_timedwait. The waiter must recheck its condition in a loop because waking does not itself establish that the condition is true. section 20.5

Signal a waiting draw thread

After updating shared game state, a thread can notify the drawing thread with: cnd_signal(&L->draw); The signaling thread holds L->mtx while changing the state and issuing the signal. The draw thread waits on L->draw with that same mutex, then reacquires the mutex before inspecting the updated state. section 20.5

Use cnd_signal safely by following these rules:

  • Change the data forming the condition, signal the condition variable, and protect both operations with the mutex used by the waiter. section 21.2
  • Have the waiter test its condition in a while loop, including termination conditions such as L->finished. section 20.5
  • Use cnd_broadcast instead when every waiting thread must be woken. section 20.5

How Modern C, Third Edition covers it

How deep it goes
Explains wakeup behavior, condition loops, mutex coupling, and mutex-mediated synchronization, but not implementation internals.
Examples
Demonstrates account, update, and draw threads signaling condition variables while coordinating shared game state.
What it assumes
Assumes mutexes, condition variables, critical sections, and shared-state conditions while defining their interaction through examples.
What you can do after
Operate/configure it to wake one correctly synchronized waiter without assuming that waking proves the condition.
How it connects
Connects condition variables with mutexes, cnd_wait, cnd_timedwait, cnd_broadcast, critical sections, and release-acquire semantics.

Also explained in

Compare how 2 books explain cnd_signal →

Related concepts

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