atomic type
A number the hardware can update in one indivisible step, safely from many threads.
std::sync::atomic types (AtomicUsize, AtomicBool...) provide lock-free load, store and read-modify-write operations such as fetch_add, each with a memory ordering.
Loading interactive…
Examples
Two threads each calling
scanned.fetch_add(1, Ordering::Relaxed)1,000 times on oneAtomicUsizealways end at 2,000, with no lock.
See also