From b426a242e3da27e9a407f9f896bcb86d347f76d1 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Sun, 8 Mar 2015 16:10:19 -0400 Subject: [PATCH] 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. --- src/doc/intro.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/intro.md b/src/doc/intro.md index 3e5b8ec6bef8..9e575abeee21 100644 --- a/src/doc/intro.md +++ b/src/doc/intro.md @@ -430,7 +430,7 @@ fn main() { thread::scoped(move || { numbers[i] += 1; println!("numbers[{}] is {}", i, numbers[i]); - }); + }) }).collect(); } ``` @@ -442,7 +442,7 @@ It gives us this error: 7 thread::scoped(move || { 8 numbers[i] += 1; 9 println!("numbers[{}] is {}", i, numbers[i]); -10 }); +10 }) error: aborting due to previous error ``` @@ -483,7 +483,7 @@ fn main() { let mut array = number.lock().unwrap(); array[i] += 1; println!("numbers[{}] is {}", i, array[i]); - }); + }) }).collect(); } ``` @@ -543,7 +543,7 @@ fn main() { let guards: Vec<_> = (0..3).map(|i| { thread::scoped(move || { println!("{}", numbers[i]); - }); + }) }).collect(); } ```