I understand atomicity can be guaranteed on operations like xsub()
, without using the LOCK
prefix, by relying on the cache coherency protocol (MESI/MES
There is no xsub
instruction in x86, but there is an xadd
;)
You should read the section about the LOCK
prefix in the Instruction Set Reference, and the section 8.1 LOCKED ATOMIC OPERATIONS in the Software Developer's Manual Volume 3A: System Programming Guide, Part 1.
The single CPU refers to a single core nowadays, with its own cache. When you have multiple caches for multiple cores (physically in the same or separate cpu chips) they use some cache coherency protocol. In case of MESI
, the core executing the atomic instruction will first ensure it has ownership of the cache line containing the operand and marks it modified
, additionally locking it. If another core needs the cache line, it will do a read operation which the owner core will snoop and delay the answer until the atomic operation completes.
On single-cpu single-core systems, most instructions are atomic with respect to threading except for string instructions using a REP
prefix because scheduling interrupts and thus context switches only happen on instruction boundaries. A hardware device could however observe non-atomic behaviour.