Skip to content

Commit cbdc52e

Browse files
committed
Expand a bit on thread::park spurious wakeups
Fixes #26475
1 parent 4e51763 commit cbdc52e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/libstd/thread/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,25 @@ pub fn sleep(dur: Duration) {
508508
imp::Thread::sleep(dur)
509509
}
510510

511-
/// Blocks unless or until the current thread's token is made available (may wake spuriously).
511+
/// Blocks unless or until the current thread's token is made available.
512512
///
513-
/// See the module doc for more detail.
513+
/// Every thread is equipped with some basic low-level blocking support, via
514+
/// the `park()` function and the [`unpark()`][unpark] method. These can be
515+
/// used as a more CPU-efficient implementation of a spinlock.
516+
///
517+
/// [unpark]: struct.Thread.html#method.unpark
518+
///
519+
/// The API is typically used by acquiring a handle to the current thread,
520+
/// placing that handle in a shared data structure so that other threads can
521+
/// find it, and then parking (in a loop with a check for the token actually
522+
/// being acquired).
523+
///
524+
/// A call to `park` does not guarantee that the thread will remain parked
525+
/// forever, and callers should be prepared for this possibility.
526+
///
527+
/// See the [module documentation][thread] for more detail.
528+
///
529+
/// [thread]: index.html
514530
//
515531
// The implementation currently uses the trivial strategy of a Mutex+Condvar
516532
// with wakeup flag, which does not actually allow spurious wakeups. In the

0 commit comments

Comments
 (0)