Two things happen here:
The compiler is given an opaque block to insert into the output instruction stream. As it does not know which data is accessed inside the block, it cannot reorder the other statements around it.
The xchg
instruction performs an atomic read-modify-write operation, which requires ordering on the memory bus, so the CPU enforces a memory barrier.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…