Once std::thread::scope[1] is stabilised, in a lot of cases you're not going to need to wrap your Mutexes in Arcs anymore:
#![feature(scoped_threads)]
use std::thread;
use std::sync::Mutex;
fn main() {
let a = Mutex::new(0u32);
thread::scope(|s| {
s.spawn(|| {
*a.lock().unwrap() += 1;
});
s.spawn(|| {
*a.lock().unwrap() += 1;
});
});
assert_eq!(*a.lock().unwrap(), 2);
}
A nice glimpse of structured concurrency.[1]: <https://doc.rust-lang.org/std/thread/fn.scope.html>
Edit: removed unnecessary "mut" from declaration of "a".