Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused_variables, unused_imports)]
- use std::{
- rc::Rc,
- sync::{Arc, Mutex},
- thread,
- };
- fn main() {
- let users1 = Arc::new(Mutex::new(vec!["alice", "bob"]));
- let users2 = users1.clone();
- thread::spawn(move || {
- let mut guard = users1.lock().unwrap();
- let n = guard.len();
- guard.push("pedro");
- });
- thread::spawn(move || {
- let guard = users2.lock().unwrap();
- let n = guard.len();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement