Skip to content

Commit d985625

Browse files
committed
Auto merge of #41811 - gamazeps:thread-panicking-doc, r=frewsxcv
[DOC] Improve `thread::panicking` documentaion. Part of #29378 Takes care of: `panicking` could use some more advice on when to use this. I mays have done a poor choice of introducing `Mutex`s. r? @steveklabnik
2 parents 8d19877 + 12efc9d commit d985625

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/thread/mod.rs

+12
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)