diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2022-03-09 10:17:49 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2022-03-09 15:20:00 +0100 |
| commit | 4d56c1563c5ae75acbcb8c163296561a6e17e47a (patch) | |
| tree | 6e28eedd35676f3d55b55400dc5b35afe4cc4178 /library/std/src/thread | |
| parent | 6045c34f15d463c7d51104b968c1eabc5275b9c1 (diff) | |
| download | rust-4d56c1563c5ae75acbcb8c163296561a6e17e47a.tar.gz rust-4d56c1563c5ae75acbcb8c163296561a6e17e47a.zip | |
Add documentation about lifetimes to thread::scope.
Diffstat (limited to 'library/std/src/thread')
| -rw-r--r-- | library/std/src/thread/scoped.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/library/std/src/thread/scoped.rs b/library/std/src/thread/scoped.rs index 4af58f1a380..c4847b529a3 100644 --- a/library/std/src/thread/scoped.rs +++ b/library/std/src/thread/scoped.rs @@ -107,6 +107,24 @@ impl ScopeData { /// a.push(4); /// assert_eq!(x, a.len()); /// ``` +/// +/// # Lifetimes +/// +/// Scoped threads involve two lifetimes: `'scope` and `'env`. +/// +/// The `'scope` lifetime represents the lifetime of the scope itself. +/// That is: the time during which new scoped threads may be spawned, +/// and also the time during which they might still be running. +/// Once this lifetime ends, all scoped threads are joined. +/// This lifetime starts within the `scope` function, before `f` (the argument to `scope`) starts. +/// It ends after `f` returns and all scoped threads have been joined, but before `scope` returns. +/// +/// The `'env` lifetime represents the lifetime of whatever is borrowed by the scoped threads. +/// This lifetime must outlast the call to `scope`, and thus cannot be smaller than `'scope`. +/// It can be as small as the call to `scope`, meaning that anything that outlives this call, +/// such as local variables defined right before the scope, can be borrowed by the scoped threads. +/// +/// The `'env: 'scope` bound is part of the definition of the `Scope` type. #[track_caller] pub fn scope<'env, F, T>(f: F) -> T where |
