std-type

AtomicUsize: pointer-width unsigned integer

Use an atomic integer with the width of usize on targets supporting pointer-width atomics. Share it through a scoped reference or Arc. A fixed-size counter does not become arbitrary precision. Expected stdout (not executed): 8 Common mistake: Assuming usize has a fixed 64-bit width on every target.

Formal Syntax & Structure

rust syntaxrust
AtomicUsize::new(value: usize)

Working Example

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