Compare and swap

This is a common atomic instruction that exists on many CPU architectures. (x86: cmpxchg, SPARC: cas). It compares a value in memory with a value in a register, and if they match, overwrites the value in memory with a third value. If successful, the operation sets a status flag that can be used for branching. This can be used to efficiently implement spinlocks.

See also Atomic instruction and Spinlock.

Get Oracle JRockit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.