summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2024-05-21 14:48:46 -0400
committerBotahamec <botahamec@outlook.com>2024-05-21 14:48:46 -0400
commitcf49f2900fe3c7abd1bbadacfdc745d6b5bbc235 (patch)
treea3b4000f0533ae61d4fa53380641f7f9a896bd49 /examples
parenta4625296cb98a68a590ae1aa78b07f190a850f37 (diff)
Fix the Dining Philosophers Problem
Diffstat (limited to 'examples')
-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();