What is Compare-and-swap?

An atomic instruction that writes a new value only if memory still holds an expected value. Wrapped in a retry loop, it enables lock-free updates.

Field: Multicore & Synchronization

Compare-and-swap in the explanations

Questions that mention Compare-and-swap (2)

  1. What does the atomic CAS (compare-and-swap) instruction do?
  2. Which describes an atomic instruction?

Related terms

Atomic instruction Load-reserved/store-conditional (LR/SC) ABA problem Acquire-release semantics Barrier synchronization Bus snooping Condition variable Critical section Data race Deadlock

Back to the glossary