CMXCHG
is truly atomic(asserts a bus lock) on a multiprocessor system only when it is prefixed with LOCK
. These days snooping based cache coherence protocols are being used which eliminates the need for the fence(bus lock).
- Coming to second part of the question(the value would anyways be changed). YES in that case the
CMPXCHG
instruction fails but nevertheless is still atomic with respect to all the processors.
Bottom line: Lock prefix makes the CMPXCHG
a multiprocessor barrier instruction.