Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

C++ Atomics and Memory Ordering

Status Draft outlineSection High-Performance C++

An atomic operation prevents a data race only for the object and ordering it actually governs. Correct lock-free code requires an explicit happens-before argument and a safe lifetime strategy.

Planned model

Build a single-producer/single-consumer ring from ordinary storage and atomic indices. Animate publication, observation, acquire/release edges, wraparound, and cache-line ownership.

Questions

  • What invariant assigns each slot to exactly one owner?
  • Which write publishes the payload, and which read observes it?
  • What changes when weak ordering, false sharing, or object reclamation enters?

Exercise

Write the happens-before proof for one enqueue and dequeue before writing any implementation code.