Skip to content

Commit e12c420

Browse files
committed
Expand a bit on clone() in Dining Philosophers
Fixes #25597
1 parent 7b0f2af commit e12c420

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/doc/trpl/dining-philosophers.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,13 @@ let handles: Vec<_> = philosophers.into_iter().map(|p| {
674674

675675
Finally, inside of our `map()`/`collect()` loop, we call `table.clone()`. The
676676
`clone()` method on `Arc<T>` is what bumps up the reference count, and when it
677-
goes out of scope, it decrements the count. You’ll notice we can introduce a
678-
new binding to `table` here, and it will shadow the old one. This is often used
679-
so that you don’t need to come up with two unique names.
677+
goes out of scope, it decrements the count. This is needed so that we know how
678+
many references to `table` exist across our threads. If we didn’t have a count,
679+
we wouldn’t know how to deallocate it.
680+
681+
You’ll notice we can introduce a new binding to `table` here, and it will
682+
shadow the old one. This is often used so that you don’t need to come up with
683+
two unique names.
680684

681685
With this, our program works! Only two philosophers can eat at any one time,
682686
and so you’ll get some output like this:

0 commit comments

Comments
 (0)