@@ -20,6 +20,9 @@ union Data<T, F> {
20
20
/// A value which is initialized on the first access.
21
21
///
22
22
/// 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.
23
26
///
24
27
/// [`LazyCell`]: crate::cell::LazyCell
25
28
///
@@ -81,8 +84,7 @@ pub struct LazyLock<T, F = fn() -> T> {
81
84
}
82
85
83
86
impl < 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.
86
88
#[ inline]
87
89
#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
88
90
pub const fn new ( f : F ) -> LazyLock < T , F > {
@@ -134,9 +136,11 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
134
136
}
135
137
}
136
138
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.
140
144
///
141
145
/// # Examples
142
146
///
@@ -204,6 +208,11 @@ impl<T, F> Drop for LazyLock<T, F> {
204
208
impl < T , F : FnOnce ( ) -> T > Deref for LazyLock < T , F > {
205
209
type Target = T ;
206
210
211
+ /// Dereferences the value.
212
+ ///
213
+ /// This method will block the calling thread if another initialization
214
+ /// routine is currently running.
215
+ ///
207
216
#[ inline]
208
217
fn deref ( & self ) -> & T {
209
218
LazyLock :: force ( self )
@@ -232,7 +241,7 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
232
241
}
233
242
234
243
// 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`.
236
245
#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
237
246
unsafe impl < T : Sync + Send , F : Send > Sync for LazyLock < T , F > { }
238
247
// auto-derived `Send` impl is OK.
0 commit comments