MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

11_multithreading/rust/lock_object.rs:3–22  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1use std::sync::{Arc, Mutex};
2
3fn main() {
4 let x = vec![0, 0];
5 let data = Arc::new(Mutex::new(x));
6 let mut handles = vec![];
7
8 for _ in 0..10 {
9 let mydata = data.clone();
10 let h = std::thread::spawn(move || {
11 let mut y = mydata.lock().unwrap();
12 for _ in 0..100_000 {
13 y[0] += 1;
14 }
15 });
16 handles.push(h);
17 }
18 for h in handles {
19 h.join().unwrap();
20 }
21 println!("{:?}", *data.lock().unwrap());
22}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected