Skip to content

Commit 0833783

Browse files
Jade WibbelsJade Wibbels
authored andcommitted
added formatting
1 parent df9a86d commit 0833783

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

module2/data_race/src/main.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Mutex that protects the data vector, and then we spawn three threads
1+
// Mutex that protects the data vector, and then we spawn three threads
22
//that each acquire a lock on the mutex and modify an element of the vector.
33

44
use std::sync::Mutex;
@@ -7,14 +7,16 @@ use std::thread;
77
fn main() {
88
let data = Mutex::new(vec![1, 2, 3]);
99

10-
let handles: Vec<_> = (0..3).map(|i| {
11-
let data = data.lock().unwrap().clone();
12-
thread::spawn(move || {
13-
let mut data = data;
14-
data[i] += 1;
15-
println!("{:?}", data);
10+
let handles: Vec<_> = (0..3)
11+
.map(|i| {
12+
let data = data.lock().unwrap().clone();
13+
thread::spawn(move || {
14+
let mut data = data;
15+
data[i] += 1;
16+
println!("{:?}", data);
17+
})
1618
})
17-
}).collect();
19+
.collect();
1820

1921
for handle in handles {
2022
handle.join().unwrap();
@@ -41,4 +43,4 @@ fn main() {
4143
4244
// No data race can occur, this will not compile.
4345
}
44-
*/
46+
*/

0 commit comments

Comments
 (0)