From 2616960be2493e1cdba95cc297bb2dbd520ad7c8 Mon Sep 17 00:00:00 2001 From: Erik Jensen Date: Sun, 28 Feb 2021 12:57:38 -0800 Subject: [PATCH] Clarify that SyncOnceCell::set blocks. Reading the discussion of this feature, I gained the mistaken impression that neither `set` nor `get` blocked, and thus calling `get` immediately after `set` was not guaranteed to succeed. It turns out that `set` *does* block, guaranteeing that the cell contains a value once `set` returns. This change updates the documentation to state that explicitly. --- library/std/src/lazy.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index aec2a2aa639ed..974851a8bd634 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -177,7 +177,10 @@ impl SyncOnceCell { /// Sets the contents of this cell to `value`. /// - /// Returns `Ok(())` if the cell's value was updated. + /// May block if another thread is currently attempting to initialize the cell. The cell is + /// guaranteed to contain a value when set returns, though not necessarily the one provided. + /// + /// Returns `Ok(())` if the cell's value was set by this call. /// /// # Examples ///