Skip to content

Instantly share code, notes, and snippets.

@pftbest
Created July 16, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pftbest/2aaf41f00043f216565d33514e2d0fec to your computer and use it in GitHub Desktop.
Save pftbest/2aaf41f00043f216565d33514e2d0fec to your computer and use it in GitHub Desktop.
use std::thread;
use std::sync::Arc;
fn main() {
let a1 = Arc::new(0);
let mut a2 = a1.clone();
let t1 = thread::spawn(
move || {
for _ in 0..10 {
let _z: u32 = *a1;
}
drop(a1);
}
);
let t2 = thread::spawn(
move || {
loop {
match Arc::get_mut(&mut a2) {
None => {}
Some(m) => {
*m = 1u32;
return;
}
}
}
}
);
t2.join().unwrap();
t1.join().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment