std-method

Atomic get_mut: exclusive access

An exclusive mutable borrow of the atomic object rules out simultaneous safe access through shared references. The returned reference permits ordinary mutation under that exclusivity. Expected stdout (not executed): 9 Common mistake: Trying to obtain exclusive mutable access while another worker still borrows the atomic.

Formal Syntax & Structure

rust syntaxrust
n.get_mut() -> &mut usize

Working Example

Example Snippetrust
fn main() {    use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};    let mut n = AtomicUsize::new(1);    *n.get_mut() = 9;    println!("{}", n.load(Relaxed));}
Rust Reference