31 Atomic operations library [atomics]

31.11 Fences [atomics.fences]

This subclause 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 or 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
 ]