A robot planning service can read a shared identifier, pause, and later find that same identifier still present. An atomic compare-and-swap may then succeed even though another participant changed the state twice during the pause. The operation compared the present value with an expected value; it did not compare the intervening history.

This distinction is called the ABA problem. The original example here uses logical software records rather than physical robot actions or unmanaged memory. It isolates what a current-value comparison establishes and what extra information a generation field can preserve. No concurrent program or cited API was executed.

Specify the comparison contract

Write CAS(expected, replacement) for an ideal atomic operation on one shared cell. It replaces that cell only if its current value equals expected. The comparison and conditional replacement form one indivisible operation in the declared model. Another writer cannot slip between those two parts.

Microsoft documents that current-value contract for InterlockedCompareExchange, which returns the cell's initial value. An application determines success by comparing that return with its expected value. Oracle's AtomicStampedReference instead supports an atomically maintained reference-and-integer pair. Its compareAndSet checks both the reference identity and the expected stamp.

The two interfaces motivate the abstractions below. They are not interchangeable source-code signatures, and neither documentation claims that a successful operation certifies an unchanged history. Reference identity also differs from an application's chosen notion of equal record contents.

Construct two indistinguishable current states

Let a shared cell contain logical record identifier A. Worker W reads A and computes a proposed replacement C. Its calculation assumes the generation of A that existed at that read. W then pauses before attempting CAS(A,C).

Consider history H0: no other participant changes the cell. W resumes, sees the expected current value A at its atomic comparison, and replaces it with C. The intended generation assumption holds in this history.

Now consider H1. While W is paused, worker V changes A to B. V later changes B back to A, representing a new generation of that logical identifier. W resumes and performs exactly the same CAS(A,C). Its comparison again succeeds, because the current value is A.

The states presented to the untagged comparison are identical. The histories are different. In H1 the success does not validate the generation-specific calculation made before the pause. Atomicity has not failed: each comparison and replacement can still occur as one indivisible step.

Decide whether history matters to the invariant

Not every A-to-B-to-A sequence creates an application error. If the only requirement is to replace whichever current value equals A, regardless of how it arrived there, both successes satisfy that narrower requirement. ABA becomes relevant when correctness depends on a fact that the compared representation omits.

For example, a planning record may carry a revision-specific association between an identifier and an immutable payload. Reusing A after retiring one revision can make a previously computed result stale even when the visible identifier matches. That is a missing-generation problem, distinct from two writers merely overwriting stale numeric quantities.

The remedy must therefore match the invariant. Checking one identifier cannot validate unrelated records, payload lifetime, or a whole multi-record transaction. A larger application statement needs an explicitly corresponding protected state or validation rule.

Compare a pair instead of one label

Replace the shared representation by (identifier, generation). Initially it is (A,12). W reads both components as one snapshot and plans to change them to (C,13), conditional on seeing the original pair.

In the competing history, V changes (A,12) to (B,13), then to (A,14). W's later comparison against (A,12) fails: the identifier matches but 14 differs from 12. The representation now distinguishes these two histories.

This conclusion assumes that every relevant successful state transition advances the generation and that the pair is compared atomically. Reading the identifier and stamp separately can form an inconsistent snapshot. For instance, reading identifier A before a transition and stamp 13 after a transition can produce a pair that was never stored together. Oracle provides a combined get operation for obtaining the pair.

An unconstrained writer that restores an old stamp would also defeat the intended protocol. Merely adding an integer field without specifying its update rule does not create a historical certificate.

Finite stamps eventually repeat

Suppose the example instead uses a three-bit generation, incremented modulo eight. Start at (A,6), and let another writer make eight relevant transitions while W pauses. Choose an alternating identifier sequence ending at A. The stamp progresses 7,0,1,2,3,4,5,6, returning the pair to (A,6).

W's old pair can now match again. In general, an incrementing b-bit counter repeats after 2^b increments. The tag distinguishes generations only within a protocol that excludes a complete wrap during the vulnerable observation interval, or otherwise prevents reuse from making an old observation valid again.

For a hypothetical eight-bit tag and 40 counted transitions per second, 256 transitions span 6.4 seconds. That arithmetic is not a concurrency guarantee: actual pauses and transition bursts need their own bounds. A larger tag enlarges the cycle without making it infinite.

Separate validation from progress and lifetime

A failed comparison generally means that the caller must reconsider its obsolete snapshot before making another proposal. Repeating the same computed replacement while silently changing only the expected value would not automatically preserve the original calculation's meaning.

A tagged comparison also does not establish fairness, a deadline, or safe reclamation of referenced storage. Logical version validation and object lifetime are separate obligations. The example assumes its logical records remain readable throughout; it supplies no memory-reclamation algorithm.

The useful audit question is concrete: which components were read together, which components were compared together, and which changes advance their generation? Answering that question makes an atomic success interpretable without turning a present-value match into an unsupported claim about everything that happened earlier.

Sources checked October 24, 2026:

Microsoft Learn, InterlockedCompareExchange, page updated May 24, 2022:

https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-interlockedcompareexchange

Oracle Java SE 25, AtomicStampedReference:

https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concurrent/atomic/AtomicStampedReference.html

Concept illustration: A small desktop robot beside a laptop showing a generic workflow provides robotics context for this analytical model. The image does not depict the article's numerical example, a verified experiment, a product specification, or deployment evidence.