姬長信(Redy)

c – x86上的原子性


8.1.2 Bus Locking

Intel 64 and IA-32 processors provide a LOCK# signal that is asserted
automatically during certain critical memory operations to lock the
system bus or equivalent link. While this output signal is asserted,
requests from other processors or bus agents for control of the bus
are blocked. Software can specify other occasions when the LOCK
semantics are to be followed by prepending the LOCK prefix to an
instruction.

它来自英特尔手册,第3卷

听起来内存上的原子操作将直接在内存(RAM)上执行.我很困惑,因为当我分析装配输出时,我看到“没什么特别的”.基本上,为std :: atomic生成的程序集输出X; X.load()只放置“额外”的mfence.但是,它负责正确的内存排序,而不是原子性.如果我理解正确,X.store(2)只是mov [某处],$2.就这样.它似乎没有“跳过”缓存.我知道将对齐(例如int)移动到内存是原子的.但是,我很困惑.

所以,我提出了疑问,但主要问题是:

CPU如何在内部实现原子操作?