liveBook · Manning

Synchronizes-with relation

As explained in Modern C, Third Edition

A synchronizes-with relation is an ordering relationship in which an acquire evaluation reads a value written by a release evaluation in another thread.

A synchronizes-with relation orders evaluations across threads: an acquire evaluation synchronizes with a release evaluation when it reads the value written by that evaluation. For atomic objects, the write is known to have happened before the corresponding read. section 21.1

Two threads sharing an atomic

Suppose thread A modifies atomic x and thread B later reads the value that A wrote. That read synchronizes with A's modification. The same pattern appears when one thread writes true to an atomic finished flag and another thread observes true: the observing thread can then see modifications made before the write. section 21.1

The relation is illustrated through these rules:

  • Atomic modifications have a modification order consistent with each thread's sequenced-before order. section 21.1
  • A read synchronizes when it observes a value written by another thread's modification. section 21.1
  • If competing threads write the same atomic flag, one write occurs first, and a later observing read can establish the ordering. section 21.1
Figure 21.1 Two threads that synchronize via an atomic. The circles present the modifications of object x. The bars below the threads represent information about the state of A, and those above represent information about the state of B.
figure

Use the figure to trace modifications of atomic x and identify where the two threads synchronize. section 21.1

How Modern C, Third Edition covers it

How deep it goes
Defines the relation through modification order and concrete reads, without developing a complete memory-model formalism.
Examples
Uses atomic x across two threads and an atomic finished flag coordinating input and account threads.
What it assumes
Assumes threads and atomic objects while relating their operations through modification and sequencing orders.
What you can do after
Evaluate/understand when an atomic read observes another thread's write and thereby orders earlier modifications.
How it connects
Connects atomic objects with modification order, sequenced-before order, and the happened-before relation.

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, Third Edition. The section links point to the parts of the book it draws on.