Home Knowledge Base Memory Barrier / Fence

Memory Barrier / Fence — a CPU instruction that enforces ordering of memory operations, preventing the hardware from reordering reads and writes in ways that break concurrent algorithms.

The Problem

Example

// Thread 1:               // Thread 2:
data = 42;                 while (!ready) {}  // spin
ready = true;              print(data);      // might print 0!

Without a memory barrier, Thread 1's writes might be reordered or not visible to Thread 2.

Types of Barriers

Memory Models

Memory barriers are foundational to lock-free programming and are what make atomic operations correct across cores.

memory barriermemory fencememory ordering

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.