about summary refs log tree commit diff
path: root/library/std/src/sync
diff options
context:
space:
mode:
authorBehnam Esfahbod <behnam@zwnj.org>2024-01-11 15:55:50 -0800
committerBehnam Esfahbod <behnam+git@oneschema.co>2024-01-14 10:28:13 -0800
commita596159dca825a02270335d4b90b8fcb128b2d11 (patch)
tree52f1671b0d73a81bd6900c2ef10dc340e40a6e5b /library/std/src/sync
parent62d7ed4a6775c4490e493093ca98ef7c215b835b (diff)
downloadrust-a596159dca825a02270335d4b90b8fcb128b2d11.tar.gz
rust-a596159dca825a02270335d4b90b8fcb128b2d11.zip
std: Doc blocking behavior of LazyLock methods
Diffstat (limited to 'library/std/src/sync')
-rw-r--r--library/std/src/sync/lazy_lock.rs21
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.