Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::{thread,time};
- use std::sync::{Arc, RwLock};
- use std::borrow::Cow;
- fn main() {
- let mut list=Cow::from(vec![2,3,5,7,11,13,17]);
- let shared=Arc::new(RwLock::new(list.clone()));
- let h={
- let mut shared=shared.clone();
- thread::spawn(move || {
- let list_copy=shared.read().unwrap().clone();
- println!("{:?}", list_copy);
- })
- };
- list.to_mut().push(19);
- //Comment the sleep line and the other thread should get the new list.
- thread::sleep(time::Duration::from_millis(10));
- *shared.write().unwrap()=list.clone();
- h.join().unwrap();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement