Expand a bit on clone() in Dining Philosophers

Fixes #25597
This commit is contained in:
Steve Klabnik 2015-06-09 15:24:44 -04:00
parent 7b0f2af27f
commit e12c420522

View File

@ -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<T>` is what bumps up the reference count, and when it
goes out of scope, it decrements the count. Youll notice we can introduce a
new binding to `table` here, and it will shadow the old one. This is often used
so that you dont 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 didnt have a count,
we wouldnt know how to deallocate it.
Youll notice we can introduce a new binding to `table` here, and it will
shadow the old one. This is often used so that you dont need to come up with
two unique names.
With this, our program works! Only two philosophers can eat at any one time,
and so youll get some output like this: