std-method

Atomic load: read one value

Read the current value according to the chosen memory ordering. A load is a snapshot, not a reservation: another worker may change the value before the next operation. Expected stdout (not executed): 12 20 Common mistake: Using a loaded value as a guarantee that later operations see unchanged state.

Formal Syntax & Structure

rust syntaxrust
value.load(order: Ordering) -> usize

Working Example

Example Snippetrust
fn main() {    use std::sync::atomic::{AtomicUsize, Ordering};    let x = AtomicUsize::new(12);    let snapshot = x.load(Ordering::Relaxed);    x.store(20, Ordering::Relaxed);    println!("{} {}", snapshot, x.load(Ordering::Relaxed));}
Rust Reference