diff options
| author | bors <bors@rust-lang.org> | 2024-01-15 16:45:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-15 16:45:41 +0000 |
| commit | 67e7b844253f6e7d4608eb4b4418dfdd80f1ac65 (patch) | |
| tree | ab1c917354c87f3eca64ad12cbb43565137b2cd3 /library/std/src/sync | |
| parent | 1ead4761e9e2f056385768614c23ffa7acb6a19e (diff) | |
| parent | 82f38ab62e962588f9af5437db9438496983b4ab (diff) | |
| download | rust-67e7b844253f6e7d4608eb4b4418dfdd80f1ac65.tar.gz rust-67e7b844253f6e7d4608eb4b4418dfdd80f1ac65.zip | |
Auto merge of #119987 - matthiaskrgr:rollup-f7lkx4w, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #119818 (Silence some follow-up errors [3/x]) - #119870 (std: Doc blocking behavior of LazyLock) - #119897 (`OutputTypeParameterMismatch` -> `SignatureMismatch`) - #119963 (Fix `allow_internal_unstable` for `(min_)specialization`) - #119971 (Use `zip_eq` to enforce that things being zipped have equal sizes) - #119974 (Minor `trimmed_def_paths` improvements) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sync')
| -rw-r--r-- | library/std/src/sync/lazy_lock.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs index 3598598cfa0..27b59cfc8c2 100644 --- a/library/std/src/sync/lazy_lock.rs +++ b/library/std/src/sync/lazy_lock.rs @@ -20,6 +20,9 @@ union Data<T, F> { /// A value which is initialized on the first access. /// /// This type is a thread-safe [`LazyCell`], and can be used in statics. +/// Since initialization may be called from multiple threads, any +/// dereferencing call will block the calling thread if another +/// initialization routine is currently running. /// /// [`LazyCell`]: crate::cell::LazyCell /// @@ -81,8 +84,7 @@ pub struct LazyLock<T, F = fn() -> T> { } impl<T, F: FnOnce() -> T> LazyLock<T, F> { - /// Creates a new lazy value with the given initializing - /// function. + /// Creates a new lazy value with the given initializing function. #[inline] #[unstable(feature = "lazy_cell", issue = "109736")] pub const fn new(f: F) -> LazyLock<T, F> { @@ -134,9 +136,11 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> { } } - /// Forces the evaluation of this lazy value and - /// returns a reference to result. This is equivalent - /// to the `Deref` impl, but is explicit. + /// Forces the evaluation of this lazy value and returns a reference to + /// result. This is equivalent to the `Deref` impl, but is explicit. + /// + /// This method will block the calling thread if another initialization + /// routine is currently running. /// /// # Examples /// @@ -204,6 +208,11 @@ impl<T, F> Drop for LazyLock<T, F> { impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> { type Target = T; + /// Dereferences the value. + /// + /// This method will block the calling thread if another initialization + /// routine is currently running. + /// #[inline] fn deref(&self) -> &T { LazyLock::force(self) @@ -232,7 +241,7 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> { } // We never create a `&F` from a `&LazyLock<T, F>` so it is fine -// to not impl `Sync` for `F` +// to not impl `Sync` for `F`. #[unstable(feature = "lazy_cell", issue = "109736")] unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F> {} // auto-derived `Send` impl is OK. |
