Skip to content

Commit 12efc9d

Browse files
author
Felix Raimundo
committed
Improve thread::panicking documentaion.
Part of #29378
1 parent ced823e commit 12efc9d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/thread/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ pub fn yield_now() {
458458

459459
/// Determines whether the current thread is unwinding because of panic.
460460
///
461+
/// A common use of this feature is to poison shared resources when writing
462+
/// unsafe code, by checking `panicking` when the `drop` is called.
463+
///
464+
/// This is usually not needed when writing safe code, as [`Mutex`es][Mutex]
465+
/// already poison themselves when a thread panics while holding the lock.
466+
///
467+
/// This can also be used in multithreaded applications, in order to send a
468+
/// message to other threads warning that a thread has panicked (e.g. for
469+
/// monitoring purposes).
470+
///
461471
/// # Examples
462472
///
463473
/// ```should_panic
@@ -486,6 +496,8 @@ pub fn yield_now() {
486496
/// panic!()
487497
/// }
488498
/// ```
499+
///
500+
/// [Mutex]: ../../std/sync/struct.Mutex.html
489501
#[inline]
490502
#[stable(feature = "rust1", since = "1.0.0")]
491503
pub fn panicking() -> bool {

0 commit comments

Comments
 (0)