From e12c4205220a6e1114493aa4501cc04e48d8693b Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 15:24:44 -0400 Subject: [PATCH] Expand a bit on clone() in Dining Philosophers Fixes #25597 --- src/doc/trpl/dining-philosophers.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/dining-philosophers.md b/src/doc/trpl/dining-philosophers.md index a18d9bb442dd2..b24d50c890da4 100644 --- a/src/doc/trpl/dining-philosophers.md +++ b/src/doc/trpl/dining-philosophers.md @@ -674,9 +674,13 @@ let handles: Vec<_> = philosophers.into_iter().map(|p| { Finally, inside of our `map()`/`collect()` loop, we call `table.clone()`. The `clone()` method on `Arc` is what bumps up the reference count, and when it -goes out of scope, it decrements the count. You’ll notice we can introduce a -new binding to `table` here, and it will shadow the old one. This is often used -so that you don’t need to come up with two unique names. +goes out of scope, it decrements the count. This is needed so that we know how +many references to `table` exist across our threads. If we didn’t have a count, +we wouldn’t know how to deallocate it. + +You’ll notice we can introduce a new binding to `table` here, and it will +shadow the old one. This is often used so that you don’t need to come up with +two unique names. With this, our program works! Only two philosophers can eat at any one time, and so you’ll get some output like this: