compare-and-swap

An atomic operation that replaces a value only if it still equals an expected value, used for lock-free concurrency control.

1 articleLast mentioned

Compare-and-swap (CAS) is an atomic operation that compares the current value at a memory location with an expected value and, only if they match, replaces it with a new value; otherwise it leaves the location unchanged. Because the comparison and the replacement happen as a single indivisible step, when several threads or processes try to update the same value at once, exactly one succeeds and the others learn that they failed. Most CPUs provide it as an instruction, and programming languages expose it through atomic operation libraries.

CAS allows shared data to be updated safely without acquiring a lock, so it underpins lock-free data structures and conditional writes in distributed storage systems. A failed attempt must re-read the latest value and retry, so throughput drops as more writers contend for the same value.

This entry is based on AIPOST articles and widely known facts. If something is wrong, please send us a correction request.

Articles covering this entry

  • Pando: The Git Backend OpenAI Built for a 2,442% Surge in CommitsAI News ·

    …nd reference updates are recorded in a central manifest using an atomic compare-and-swap (CAS) operation, which succeeds only if nobody else changed the manifes…

    Read article

Found a mistake or missing an entry?

Wiki entries are based on AIPOST articles and widely known facts. If an entry is wrong, send us a correction request and we will check and fix it. Names from new articles are added to the wiki after the article is published.