The Intel documentation says
This instruction can be used with a
LOCK
prefix to allow the instruction to be executed atomically.
My question is
Can
CMPXCHG
operate with memory address? From the document it seems not but can anyone confirm that only works with actual VALUE in registers, not memory address?If
CMPXCHG
isn't atomic and a high level language level CAS has to be implemented throughLOCK CMPXCHG
(withLOCK
prefix), what's the purpose of introducing such an instruction at all?
(I am asking from a high level language perspective. I.e., if the lock-free algorithm has to be translated into a LOCK CMPXCHG on the x86 platform, then it's still prefixed with LOCK. That means the lock-free algorithms are not better than ones with a carefully written synchronized lock / mutex (on x86 at least). This also seems to make the naked CMPXCHG instruction pointless, as I guess the major point for introducing it, was to support such lock-free operations.)
Question&Answers:os