Skip to content

Commit b426a24

Browse files
committed
Make concurrent examples actually run concurrently
If we end the `scoped` call with a semicolon, the `JoinGuard` will be dropped and not returned from the `map`. The thread will start up and we immediately block, making for a very expensive sequential loop.
1 parent a6ebd26 commit b426a24

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/doc/intro.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ fn main() {
430430
thread::scoped(move || {
431431
numbers[i] += 1;
432432
println!("numbers[{}] is {}", i, numbers[i]);
433-
});
433+
})
434434
}).collect();
435435
}
436436
```
@@ -442,7 +442,7 @@ It gives us this error:
442442
7 thread::scoped(move || {
443443
8 numbers[i] += 1;
444444
9 println!("numbers[{}] is {}", i, numbers[i]);
445-
10 });
445+
10 })
446446
error: aborting due to previous error
447447
```
448448
@@ -483,7 +483,7 @@ fn main() {
483483
let mut array = number.lock().unwrap();
484484
array[i] += 1;
485485
println!("numbers[{}] is {}", i, array[i]);
486-
});
486+
})
487487
}).collect();
488488
}
489489
```
@@ -543,7 +543,7 @@ fn main() {
543543
let guards: Vec<_> = (0..3).map(|i| {
544544
thread::scoped(move || {
545545
println!("{}", numbers[i]);
546-
});
546+
})
547547
}).collect();
548548
}
549549
```

0 commit comments

Comments
 (0)