Explain the C++ memory model and the difference between 'sequentially consistent' and 'relaxed' memory ordering.

Last updated 21 June 2026

  • The C++ memory model defines what threads can observe and which compiler/CPU reorderings are legal. std::atomic operations take a memory order to constrain reordering.

  • memory_order_seq_cst (the default) gives all threads one total order of operations. It is easiest to reason about but slowest due to full barriers.

  • memory_order_relaxed guarantees only atomicity with no ordering (fine for independent counters). Acquire/release sits between, linking a release store to an acquire load.

  • https://www.geeksforgeeks.org/cpp/memory-model-in-cpp-11/
  • https://www.ramtintjb.com/blog/memory-ordering
  • https://github.com/jemmy512/software-engineer
  • https://esequeira.com/posts/performance-impact-of-cpp-memory-order-vs-x86-strong-ordering/
  • https://stackoverflow.com/questions/12346487/what-do-each-memory-order-mean
  • https://www.geeksforgeeks.org/operating-systems/consistency-model-in-distributed-system/
All C++ interview questions