源码

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< int>生成的程序集输出X; X.load()只放置“额外”的mfence.但是,它负责正确的内存排序,而不是原子性.如果我理解正确,X.store(2)只是mov [某处],$2.就这样.它似乎没有“跳过”缓存.我知道将对齐(例如int)移动到内存是原子的.但是,我很困惑.

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

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

(0)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/c-x86shangdeyuanzixing.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9 月 19, 2019 at 12:57 上午

热评文章