The Three Fences

This lesson gives an overview of the acquire, release, and full fences used in C++ as memory barriers.

We'll cover the following...

Typically, three kinds of fences are used: full fence, acquire fence and release fence. As a reminder, acquire is a load, and release is a store operation. What happens if I place one of the three memory barriers between the four combinations of load and store operations?

  • Full fence: A full fence std::atomic_thread_fence() between two arbitrary operations prevents the reordering of these operations, but guarantees that it won’t hold for StoreLoad operations. Also, they can be reordered.

  • Acquire fence: An acquire fence std::atomic_thread_fence(std::memory_order_acquire) prevents a ...