A read-modify-write operation atomically reads an object, computes or selects a new value, and writes that value in one indivisible operation. In concurrent code, it can synchronize on the read side with one thread and on the write side with others. section 21.1
Atomic update versus assignment
With _Atomic(unsigned) x = 11;, ++x and x-- are read-modify-write operations. By contrast, x = 31 and x = 5 are writes, while unsigned y = x is a read. The atomic update combines its read and write into one operation. section 21.1
Recognized forms include:
- Calls to atomic_exchange and atomic_compare_exchange_weak for _Atomic objects. section 21.1
- Compound assignments, increment, and decrement operators for arithmetic _Atomic objects. section 21.1
- Calls to atomic_flag_test_and_set for atomic_flag. 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.
A two-thread diagram traces modifications of an atomic object and shows how read-modify-write operations participate in synchronization. section 21.1


