32 Atomic operations library [atomics]

32.9 Fences [atomics.fences]

This section introduces synchronization primitives called fences.
Fences can have acquire semantics, release semantics, or both.
A fence with acquire semantics is called an acquire fence.
A fence with release semantics is called a release fence.
A release fence A synchronizes with an acquire fence B if there exist atomic operations X and Y, both operating on some atomic object M, such that A is sequenced before X, X modifies M, Y is sequenced before B, and Y reads the value written by X or a value written by any side effect in the hypothetical release sequence X would head if it were a release operation.
A release fence A synchronizes with an atomic operation B that performs an acquire operation on an atomic object M if there exists an atomic operation X such that A is sequenced before X, X modifies M, and B reads the value written by X or a value written by any side effect in the hypothetical release sequence X would head if it were a release operation.
An atomic operation A that is a release operation on an atomic object M synchronizes with an acquire fence B if there exists some atomic operation X on M such that X is sequenced before B and reads the value written by A or a value written by any side effect in the release sequence headed by A.
extern "C" void atomic_thread_fence(memory_order order) noexcept;
Effects: Depending on the value of order, this operation:
  • has no effects, if order == memory_­order_­relaxed;
  • is an acquire fence, if order == memory_­order_­acquire || order == memory_­order_­consume;
  • is a release fence, if order == memory_­order_­release;
  • is both an acquire fence and a release fence, if order == memory_­order_­acq_­rel;
  • is a sequentially consistent acquire and release fence, if order == memory_­order_­seq_­cst.
extern "C" void atomic_signal_fence(memory_order order) noexcept;
Effects: Equivalent to atomic_­thread_­fence(order), except that the resulting ordering constraints are established only between a thread and a signal handler executed in the same thread.
[Note
:
atomic_­signal_­fence can be used to specify the order in which actions performed by the thread become visible to the signal handler.
Compiler optimizations and reorderings of loads and stores are inhibited in the same way as with atomic_­thread_­fence, but the hardware fence instructions that atomic_­thread_­fence would have inserted are not emitted.
end note
]