liveBook · Manning

Synchronizes-with relation

As explained in Modern C

A synchronizes-with relation orders evaluations in different threads when a synchronization operation in one thread observes the result of a corresponding operation in another.

A synchronizes-with relation orders evaluations in different threads when one thread reads the value written by a corresponding atomic operation in another. Synchronization supplies cross-thread ordering beyond the sequenced-before relation within one thread. section 19.1

TAKEAWAY

  • Atomic modifications of an object have a modification order consistent with each participating thread’s sequenced-before order. section 19.1
  • Two threads synchronize through an atomic when one reads the value written by the other; synchronization can also arise from certain C library calls. section 19.1

Observed writes establish synchronization

For an atomic x, suppose thread A writes 31 during --x and thread B reads that value while also modifying x. B synchronizes with A. Later, A reads the value 5 written by B and stores it in y; that observation establishes synchronization in the opposite direction. section 19.1

How Modern C covers it

How deep it goes
Defines observed-write synchronization and modification order, while deferring detailed treatment of C library synchronization.
Examples
Uses an atomic x whose threads observe values 31 and 5 written by one another.
What it assumes
Assumes sequenced-before ordering and atomic objects as prior concepts.
What you can do after
Evaluate whether two threads synchronize by checking whether one atomic operation observes the other’s written value.
How it connects
Connects sequenced-before ordering, atomic objects, modification order, and memory consistency.

Also explained in

Compare how 3 books explain synchronizes-with relation →

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.