Memory Barrier/内存屏障

目录

1 问题定义

内存屏障, 又称内存栅栏, 是一种内存访问操作中的同步指令, 其功能是保证此指令之前的 所有内存读写操作都执行后, 此指令之后的读写操作才会发起.

Intel CPU有mfence, lfence, sfence

  • sfence

The SFENCE (Store Fence) instruction controls write ordering by creating a fence for memory store operations. This instruction guarantees that the result of every store instruction that precedes the store fence in program order is globally visible before any store instruction that follows the fence. The SFENCE instruction provides an efficient way of ensuring ordering between procedures that produce weakly-ordered data and procedures that consume that data.

mfence
lfence

2 相关资料