The article explores the concept of "strongly happens before," introduced in C++20, addressing challenges in the C++ memory model related to memory orderings in concurrent programming with std::atomic. Starting with a C++ example involving three threads performing atomic operations with various memory orders (sequentially consistent, release, relaxed), it questions whether certain observed executions are possible under the C++ memory model. Key points discussed include: - Modification Order: Each atomic object has a total order of modifications, and various coherence rules define allowed relationships between atomic operations' reads and writes (write-write, read-write, write-read coherences). - Coherence-Ordered Before: Defines relationships where an atomic operation is coherence-ordered before another if it modifies the same atomic object and is observed or ordered before the second operation. Transitive properties and "read-from" relations are crucial here. - Single Total Order for SeqCst Operations: The C++ standard requires a single total order for all sequentially consistent (seqcst) atomic operations that respects strongly happens-before relations. The article points out that relaxing "strongly happens before" to the vanilla "happens before" relation can create cycles in the execution graph, making the execution invalid under the standard. - Discrepancies With Real Architectures: Some architectures like Power allow executions that the C++ model (under naive happens-before interpretation) marks invalid. The C++ committee studied whether to fix implementations or adjust the standard and chose the latter to avoid severe performance penalties. - Understanding Power Architecture's Behavior: The article delves into Power architecture's memory model using tools (herd7, rmem) and references research papers. Power uses relaxed memory models with specific synchronization constructs like sync, lwsync, hwsync, enforcing certain barriers and coherence rules. This allows memory behaviors that do not strictly preserve happens-before ordering. - Power Assembly and Synchronization Barriers: Illustrations show how barriers affect propagation and visibility of writes, clarifying why some writes and reads can appear out of order on Power despite coherence requirements. - Strongly Happens Before Definition: According to the C++ standard, "strongly happens before" extends happens-before by including conditions like sequential consistency and synchronization with release/acquire pairs that are sequentially consistent, ensuring proper ordering and avoiding cycles. - Effect on Execution Graph: The example shows that certain edges in the graph do not qualify as strongly happens-before, allowing valid total orders that reflect observed executions even on relaxed architectures. - Subtleties with Mixed Memory Orders: The article notes subtle issues arising when mixing seqcst and non-seqcst operations on the same atomic variable,