Skip to content

Commit 3712bb6

Browse files
committed
Mention park guarantee
1 parent c2bbfea commit 3712bb6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libstd/sync/once.rs

+4
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ fn wait(state_and_queue: &AtomicUsize, current_state: usize) {
469469
// dangling reference). Guard against spurious wakeups by reparking
470470
// ourselves until we are signaled.
471471
while !node.signaled.load(Ordering::Acquire) {
472+
// If the managing thread happens to signal and unpark us before we can
473+
// park ourselves, the result could be this thread never gets unparked.
474+
// Luckily `park` comes with the guarantee that if it got an `unpark`
475+
// just before on an unparked thread is does not park.
472476
thread::park();
473477
}
474478
}

0 commit comments

Comments
 (0)