expression

ABA: equality does not prove unchanged history

A value can change from A to B and back to A, allowing a later comparison to succeed despite an intervening change. This fixed sequence demonstrates ABA without pointer dereferences. Real lock-free reclamation needs a verified algorithm, not just a comparison. Expected stdout (not executed): true Common mistake: Assuming successful compare_exchange proves no intervening change occurred.

Formal Syntax & Structure

rust syntaxrust
compare_exchange(expected, replacement, success, failure)

Working Example

Example Snippetrust
fn main() {    use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};    let n = AtomicUsize::new(1);    let seen = n.load(SeqCst);    n.store(2, SeqCst);    n.store(1, SeqCst);    println!("{}", n.compare_exchange(seen, 3, SeqCst, SeqCst).is_ok());}
Rust Reference