@@ -20,6 +20,9 @@ union Data<T, F> {
2020/// A value which is initialized on the first access.
2121///
2222/// This type is a thread-safe [`LazyCell`], and can be used in statics.
23+ /// Since initialization may be called from multiple threads, any
24+ /// dereferencing call will block the calling thread if another
25+ /// initialization routine is currently running.
2326///
2427/// [`LazyCell`]: crate::cell::LazyCell
2528///
@@ -81,8 +84,7 @@ pub struct LazyLock<T, F = fn() -> T> {
8184}
8285
8386impl < T , F : FnOnce ( ) -> T > LazyLock < T , F > {
84- /// Creates a new lazy value with the given initializing
85- /// function.
87+ /// Creates a new lazy value with the given initializing function.
8688 #[ inline]
8789 #[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
8890 pub const fn new ( f : F ) -> LazyLock < T , F > {
@@ -134,9 +136,11 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
134136 }
135137 }
136138
137- /// Forces the evaluation of this lazy value and
138- /// returns a reference to result. This is equivalent
139- /// to the `Deref` impl, but is explicit.
139+ /// Forces the evaluation of this lazy value and returns a reference to
140+ /// result. This is equivalent to the `Deref` impl, but is explicit.
141+ ///
142+ /// This method will block the calling thread if another initialization
143+ /// routine is currently running.
140144 ///
141145 /// # Examples
142146 ///
@@ -204,6 +208,11 @@ impl<T, F> Drop for LazyLock<T, F> {
204208impl < T , F : FnOnce ( ) -> T > Deref for LazyLock < T , F > {
205209 type Target = T ;
206210
211+ /// Dereferences the value.
212+ ///
213+ /// This method will block the calling thread if another initialization
214+ /// routine is currently running.
215+ ///
207216 #[ inline]
208217 fn deref ( & self ) -> & T {
209218 LazyLock :: force ( self )
@@ -232,7 +241,7 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
232241}
233242
234243// We never create a `&F` from a `&LazyLock<T, F>` so it is fine
235- // to not impl `Sync` for `F`
244+ // to not impl `Sync` for `F`.
236245#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
237246unsafe impl < T : Sync + Send , F : Send > Sync for LazyLock < T , F > { }
238247// auto-derived `Send` impl is OK.
0 commit comments