Skip to content

Commit 122b2ae

Browse files
std: Expand on blocking behavior of LazyLock
1 parent fdb6f58 commit 122b2ae

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/std/src/sync/lazy_lock.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ 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+
/// Therefore, any dereferencing call will block the calling thread if
24+
/// another initialization routine is currently running.
2325
///
2426
/// [`LazyCell`]: crate::cell::LazyCell
2527
///
@@ -81,8 +83,7 @@ pub struct LazyLock<T, F = fn() -> T> {
8183
}
8284

8385
impl<T, F: FnOnce() -> T> LazyLock<T, F> {
84-
/// Creates a new lazy value with the given initializing
85-
/// function.
86+
/// Creates a new lazy value with the given initializing function.
8687
#[inline]
8788
#[unstable(feature = "lazy_cell", issue = "109736")]
8889
pub const fn new(f: F) -> LazyLock<T, F> {
@@ -239,7 +240,7 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
239240
}
240241

241242
// We never create a `&F` from a `&LazyLock<T, F>` so it is fine
242-
// to not impl `Sync` for `F`
243+
// to not impl `Sync` for `F`.
243244
#[unstable(feature = "lazy_cell", issue = "109736")]
244245
unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F> {}
245246
// auto-derived `Send` impl is OK.

0 commit comments

Comments
 (0)