summaryrefslogtreecommitdiff
path: root/examples/dining_philosophers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dining_philosophers.rs')
-rw-r--r--examples/dining_philosophers.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/examples/dining_philosophers.rs b/examples/dining_philosophers.rs
index 2f2fa0d..1340564 100644
--- a/examples/dining_philosophers.rs
+++ b/examples/dining_philosophers.rs
@@ -61,9 +61,13 @@ impl Philosopher {
}
fn main() {
- let handles = PHILOSOPHERS
+ let handles: Vec<_> = PHILOSOPHERS
.iter()
- .map(|philosopher| thread::spawn(move || philosopher.cycle()));
+ .map(|philosopher| thread::spawn(move || philosopher.cycle()))
+ // The `collect` is absolutely necessary, because we're using lazy
+ // iterators. If `collect` isn't used, then the thread won't spawn
+ // until we try to join on it.
+ .collect();
for handle in handles {
_ = handle.join();