SHARE
TWEET

Untitled

a guest Jun 26th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::sync::{Arc, Mutex};
  2.  
  3. struct LockedData {
  4.     data:i32,
  5. }
  6.  
  7. fn main_no_release() {
  8.     let mutex = Arc::new(Mutex::new(LockedData{data:31}));
  9.     let guarded_data = {&mut mutex.lock().unwrap().data};
  10.     *guarded_data += 1;
  11.     println!("Hello, {}", mutex.lock().unwrap().data);  
  12. }
  13.  
  14. fn main() {
  15.     let mutex = Arc::new(Mutex::new(LockedData{data:31}));
  16.     let mut guard = mutex.lock().unwrap();
  17.     guard.data += 1;
  18.     std::mem::drop(guard);
  19.     println!("Hello, {}", mutex.lock().unwrap().data);
  20. }
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