std-module
std::sync::atomic: shared atomic state
Atomic values provide indivisible accesses to a single location. They can support shared counters and synchronization protocols, but a sequence of separate atomic operations is not necessarily indivisible. Every operation must use an appropriate ordering. Expected stdout (not executed): 3 Common mistake: Assuming atomic fields automatically make a whole struct transaction atomic.
Formal Syntax & Structure
rust syntaxrust
use std::sync::atomic::{AtomicUsize, Ordering};Working Example
Example Snippetrust
fn main() { use std::sync::atomic::{AtomicUsize, Ordering}; let n = AtomicUsize::new(0); n.fetch_add(3, Ordering::Relaxed); println!("{}", n.load(Ordering::Relaxed));}