← Quit0 / 0 correct
RustMedium1 of 104

What is the idiomatic way to share a mutable counter between threads?

let counter = Arc::new(Mutex::new(0));
for _ in 0..8 {
    let c = Arc::clone(&counter);
    thread::spawn(move || *c.lock().unwrap() += 1);
}