📝Atomic ordering

tags

§ Programming

Relaxed

No order imposed (i.e., this load/store can be reordered with other loads/stores). Only atomicity and modification order consistency is guaranteed.

Release-Acquire

All memory writes (non-atomic and relaxed atomic) before the atomic (release) store become visible to a thread that uses (acquire) load.

Release-Consume

Similar to Release-Acquire but the order is only established between dependencies. [2021-11-13 Sat]: this options requires compiler to track dependencies and doesn’t seem to be implemented widely.

Note that currently (2/2015) no known production compilers track dependency chains: consume operations are lifted to acquire operations.

The specification of release-consume ordering is being revised, and the use of memoryorderconsume is temporarily discouraged. (since C++17)

Sequentially-consistent

Similar to Release-Acquire but additionally establishes a single global order of all atomic operations that are so tagged.

  • This is the strongest guarantee and is used by default in C++. It is a safe default choice but carries performance penalty.

    Total sequential ordering requires a full memory fence CPU instruction on all multi-core systems. This may become a performance bottleneck since it forces the affected memory accesses to propagate to every core.

References

Backlinks