`Arc``Arc``RwLock``Mutex``RwLock`
use std::sync::{Arc, RwLock};
use std::vec::Vec;
use std::{thread, time};
fn main() {
let arc = Arc::new(RwLock::new(Vec::new())); // Arc
let arc2 = Arc::clone(&arc);
thread::spawn(move || {
for x in 1..=10 {
if let Ok(mut v) = arc2.write() {
v.push(x);
}
}
});
thread::sleep(time::Duration::from_secs(3));
if let Ok(v) = arc.read() {
v.iter().for_each(|n| println!("{:?}", n));
};
}
<
<