IT lexicon › Programming › Fence operation

Fence operation

Programming På svenska → Updated: 2026-11-15

CPU instruction that forces a memory barrier, ensuring prior operations become visible before subsequent ones.

A fence (often MFENCE, LFENCE, SFENCE on x86, or DMB/DSB on ARM) is an instruction that tells the processor: "stall everything, flush caches, continue." Before the fence, memory operations can be buffered, reordered, and pipelined. After it, they are committed—other threads are guaranteed to see the results. The fence itself has a cost: it forces the cache hierarchy to drain, serializes writes, and kills instruction-level parallelism.

There are flavors: an acquire fence says everything after must wait until everything before is done; a release fence holds back everything after until prior operations are visible. A full barrier enforces both. Programmers use fences when atomicity on individual variables is insufficient—when multiple writes must be presented as a unit for correctness.

← Back to the lexicon