expression
Lost updates despite atomic loads and stores
A read and a later write can be individually atomic yet still lose another update. The example explicitly simulates two workers reading the same old value before writing; no concurrency timing is involved. Expected stdout (not executed): 1 Common mistake: Equating data-race freedom with correct compound state transitions.
Formal Syntax & Structure
rust syntaxrust
load → compute → store is not one RMWWorking Example
Example Snippetrust
fn main() { use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; let n = AtomicUsize::new(0); let a = n.load(SeqCst); let b = n.load(SeqCst); n.store(a + 1, SeqCst); n.store(b + 1, SeqCst); println!("{}", n.load(SeqCst));}