share 7
parent
2f79151466
commit
f2dad4eb10
@ -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…
Reference in New Issue