From 8107a0ea2b54b591bd43e53cc02488d9676ea648 Mon Sep 17 00:00:00 2001 From: Igor Petruk Date: Mon, 23 Jan 2023 10:56:32 +0000 Subject: [PATCH] Update scoped-threads.md (#253) Adding speaker notes explaining why scoped threads work and what borrowing rules apply. --- src/concurrency/scoped-threads.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/concurrency/scoped-threads.md b/src/concurrency/scoped-threads.md index ba8f1960..1f58a828 100644 --- a/src/concurrency/scoped-threads.md +++ b/src/concurrency/scoped-threads.md @@ -31,3 +31,10 @@ fn main() { ``` [1]: https://doc.rust-lang.org/std/thread/fn.scope.html + +
+ +* The reason for that is that when the `thread::scope` function completes, all the threads are guaranteed to be joined, so they can return borrowed data. +* Normal Rust borrowing rules apply: you can either borrow mutably by one thread, or immutably by any number of threads. + +