← Quit0 / 0 correct
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);
}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);
}