master
Andrew Johnson 6 years ago
parent 2f79151466
commit f2dad4eb10

@ -68,3 +68,11 @@ path = "share4.rs"
name = "share5"
path = "share5.rs"
[[bin]]
name = "share6"
path = "share6.rs"
[[bin]]
name = "share7"
path = "share7.rs"

@ -0,0 +1,21 @@
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;
});
}
}

@ -0,0 +1,17 @@
use std::thread;
struct MyBox(u8);
unsafe impl Send for MyBox {}
unsafe impl Sync for MyBox {}
static A: MyBox = MyBox(22);
fn main() {
thread::spawn(move || {
A.0
});
thread::spawn(move || {
A.0
});
}
Loading…
Cancel
Save