SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![allow(unused_variables, unused_imports)]
  2.  
  3. use std::{
  4.     rc::Rc,
  5.     sync::{Arc, Mutex},
  6.     thread,
  7. };
  8.  
  9. fn main() {
  10.     let users1 = Arc::new(Mutex::new(vec!["alice", "bob"]));
  11.     let users2 = users1.clone();
  12.  
  13.     thread::spawn(move || {
  14.         let mut guard = users1.lock().unwrap();
  15.         let n = guard.len();
  16.         guard.push("pedro");
  17.     });
  18.  
  19.     thread::spawn(move || {
  20.         let guard = users2.lock().unwrap();
  21.         let n = guard.len();
  22.     });
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top