You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
393 B
Rust

use std::thread;
use std::sync::{Arc,Mutex};
fn main() {
let a = Arc::new(Mutex::new(vec![1, 2, 3]));
{
let a = Arc::clone(&a);
thread::spawn(move || {
let mut a = a.lock().unwrap();
(*a)[1] = 2;
});
}
{
let a = Arc::clone(&a);
thread::spawn(move || {
let mut a = a.lock().unwrap();
(*a)[1] = 3;
});
}
}