Skip to content

Memory Ordering Fence

A memory-ordering fence constrains selected memory operations around it according to a concurrency memory model.

Version
v1 · 2026-11-14 · History
Domain-specific #
14809
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering

Core Idea

A memory-ordering fence is a concurrency primitive that constrains how selected memory operations before and after a point relate under a specified memory model. Which operations are ordered, and what another thread can conclude, depend on the fence and on the surrounding operations. A write memory barrier is one specialized form; a full barrier, acquire fence and release fence have different contracts.[1][2]

How would you explain it like I'm…

The Don't-Swap Line

Inside a computer, several helpers share one notebook, and to go fast they sometimes do their writing in a mixed-up order. A fence is a special mark that says certain jobs before it must count as done before certain jobs after it. That way another helper reading the notebook isn't fooled. Different kinds of fences make different promises.

Order Rule for Shared Memory

A computer can run several workers, called threads, at the same time, and they share memory. To be fast, the computer may let some reads and writes to memory happen in a different order than the program lists them. A memory ordering fence is an instruction placed in the program that limits that reshuffling for certain reads and writes on either side of it. Different fences have different rules, so a programmer has to pick the right one and use it together with the right reads and writes for other threads to see things in a dependable order.

Memory Ordering Barrier

A Memory Ordering Fence is a tool for concurrent programs, where several threads share memory. Hardware and compilers can reorder memory operations for speed, and a memory model is the set of rules saying which orders other threads are allowed to observe. A fence placed at a point in the code constrains how selected operations before it relate to selected operations after it under that model. What gets ordered, and what another thread can safely conclude, depends on the specific fence and on the operations around it. For example, a write memory barrier only deals with ordering writes, while a full barrier, an acquire fence and a release fence each make different guarantees.

 

A Memory Ordering Fence (memory barrier) is a concurrency primitive that restricts the permitted ordering between certain memory operations preceding it and certain operations following it in program order, as defined by a particular memory model. Without such constraints, compilers and processors may reorder or delay the visibility of loads and stores, so another thread could observe effects in an unexpected order. The guarantee of a fence is contract-specific: it names which classes of operations are ordered relative to which. A write memory barrier is a specialized fence for ordering stores; a full barrier, an acquire fence and a release fence each have different contracts. What another thread may infer also depends on the surrounding operations, not just the fence alone, so reasoning about correctness requires the memory model, the fence type and the accesses on both sides.

Structural Signature

The roles are an executing thread or CPU, memory operations on either side, the fence and its ordering strength, the governing memory model, and the observations or synchronization that model permits. A constraint is meaningful only for the accesses and participants to which its contract applies.[1][2]

Examples

Linux write memory barrier. The Linux Kernel Memory Model describes WRITE_ONCE(x, 1); smp_wmb(); WRITE_ONCE(y, 1);: its write barrier orders the two marked writes in the documented model. The documentation warns that compiler transformations of unmarked C stores can defeat the intended ordering and often recommends a release store instead. This is an ordering claim, not a promise that every reader independently observes a consistent snapshot or that writes are durable on storage.[1]

C++ release and acquire fences. The C++ working draft specifies that a release fence can synchronize with an acquire fence when the specified intervening atomic operations access the same atomic object and satisfy the draft's reads-from condition. The fences alone, without those conditions, do not create that synchronization. A signal fence has a narrower scope between a thread and a signal handler executed in that thread.[2]

Boundaries and Use

A fence is not a storage cache flush and does not by itself make earlier writes durable. A garbage-collector write barrier instead performs collector bookkeeping around reference mutations. To reason about publication, identify both the publisher and reader operations, their synchronization relation and applicable memory model; a fence by itself does not repair a data race or specify a complete protocol.[1][2]

Neighborhood in Abstraction Space

Memory Ordering Fence sits in a sparse region of the domain-specific corpus (90th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (3155 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Linux kernel documentation, “Ordering,” Linux Kernel Memory Model, sections “Categories of Ordering” and “Write Memory Barrier,” https://docs.kernel.org/dev-tools/lkmm/docs/ordering.html. registry ↩a ↩b ↩c ↩d

[2] ISO C++ working draft, “Fences [atomics.fences],” https://eel.is/c++draft/atomics.fences, accessed for its stated draft synchronization rules. registry ↩a ↩b ↩c ↩d