Skip to content

Instantly share code, notes, and snippets.

@andyjsbell
Created July 22, 2020 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyjsbell/e16c23660e1edefe35e12bc56d98715d to your computer and use it in GitHub Desktop.
Save andyjsbell/e16c23660e1edefe35e12bc56d98715d to your computer and use it in GitHub Desktop.
use std::sync::{Arc, Mutex};
#[derive(Clone)]
struct Obj {
pub c: u32,
}
fn main() {
let obj = Arc::new(Mutex::new(Obj{c:0}));
let local = obj.clone();
let mut test = move || {
let mut o = local.lock().unwrap();
o.c += 1;
println!("{}", o.c);
};
obj.lock().unwrap().c = 12;
test();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment