Created
July 16, 2018 20:45
-
-
Save pftbest/2aaf41f00043f216565d33514e2d0fec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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