liveBook · Manning

Read-modify-write operation

Also called read-modify-write pattern

A read-modify-write operation reads a value from a location, modifies or selects a new value, and writes the result back to that location.

How 5 Manning books explain it

C++ Concurrency in Action, Second Edition

A read-modify-write operation atomically reads a value, modifies it, and writes the result as one operation.

How it is used
Uses atomic read-modify-write operations to update shared values and support synchronization in concurrent data structures.
How deep it goes
Explains return values, compare-exchange failures, release sequences, and cache contention through concrete C++ cases.
Examples
Uses atomic booleans, pointer arithmetic, a reference-counted lock-free stack, and a contended atomic counter.
What you can do after
Evaluate atomic updates by tracing their values, synchronization effects, and possible contention costs.

Read how C++ Concurrency in Action, Second Edition explains read-modify-write operation →

Modern C

A read-modify-write operation atomically reads an object, computes or applies a modification, and writes the resulting value as one indivisible operation.

How it is used
Coordinates atomic updates between threads while controlling visibility and synchronization through memory-order semantics.
How deep it goes
Distinguishes operation categories and explains explicit memory-order choices, but does not develop their platform-level implementation.
Examples
Uses atomic_fetch_add_explicit on an atomic counter and lists exchange, compare-exchange, compound assignment, increment, decrement, and atomic-flag forms.
What you can do after
Apply it via atomic_fetch_add_explicit or compare-exchange interfaces with an explicitly selected memory_order value.

Read how Modern C explains read-modify-write operation →

Modern C, Third Edition

A read-modify-write operation atomically reads an object, computes or selects a new value, and writes that value as one indivisible operation.

How it is used
Coordinates concurrent access by making selected atomic updates indivisible and usable for synchronization.
How deep it goes
Defines recognized forms and synchronization behavior, but stops short of implementation-level mechanics.
Examples
Uses atomic increment and decrement alongside separate reads and writes of an atomic unsigned object.
What you can do after
Evaluate/understand which atomic expressions combine reading and writing, and how those expressions synchronize between threads.

Read how Modern C, Third Edition explains read-modify-write operation →

Embedded Software with Rust

Read-modify-write reads a value, changes selected parts, and writes the result back to the same location.

How it is used
Preserves unrelated register fields while changing selected fields in peripheral configuration.
How deep it goes
Traces a PAC modify call through a volatile load, read and write proxies, and one store; the sequence remains vulnerable to races.
Examples
Updates GPIO pin 13 through CRH and contrasts BSRR writes that set or reset pins without reading first.
What you can do after
Apply field-specific register updates through a PAC modify closure while retaining other register bits.

Read how Embedded Software with Rust explains read-modify-write operation →

Grokking GPU Programming

A read-modify-write is an operation sequence that reads a value, computes an update, and writes the result back.

How it is used
Uses shared counters and accumulators to show why parallel updates can lose data.
How deep it goes
Explains the three-step update and thread interleavings, then points to atomic updates and other protections.
Examples
Uses a shared counter, bank deposits, a sum accumulator, and histogram bins to illustrate lost updates.
What you can do after
Diagnose lost or inconsistent updates by spotting shared increments or additions without atomic protection, phase separation, or single ownership.

Read how Grokking GPU Programming explains read-modify-write operation →

Also covered in

What to know first

Related concepts

Questions about read-modify-write operation

What is read-modify-write operation?

A read-modify-write operation reads a value from a location, modifies or selects a new value, and writes the result back to that location.

Which Manning books explain read-modify-write operation?

C++ Concurrency in Action, Second Edition, Modern C, Modern C, Third Edition, Embedded Software with Rust and Grokking GPU Programming.

What should I know before learning read-modify-write operation?

Manning books that teach read-modify-write operation usually introduce compare-and-swap first.

What kinds of read-modify-write operation are there?

Kinds of read-modify-write operation include test-and-set, atomic_fetch_add, fetch_add() and fetch_sub().

What is read-modify-write operation a kind of?

Read-modify-write operation is a kind of atomicity. Atomicity is the property that an operation or group of operations takes effect as an indivisible whole, without observable partial effects.

What is read-modify-write operation also called?

Read-modify-write operation is also called read-modify-write pattern.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.