A friend of mine discovered this today. Consider this code:
use std::sync::atomic::{ATOMIC_BOOL_INIT, AtomicBool, Ordering};
pub const REPO_LOCK: AtomicBool = ATOMIC_BOOL_INIT;
fn main() {
let working = REPO_LOCK.compare_and_swap(false, true, Ordering::SeqCst);
println!("REPO_LOCK = {}", working);
let working = REPO_LOCK.compare_and_swap(false, true, Ordering::SeqCst);
println!("REPO_LOCK = {}", working);
}
It is expected to print false then true, but it doesn’t.
Do you see why
?