From d718b1a79508169f10cd4b691071d4308ac15fc3 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 31 Oct 2021 15:02:38 +0100 Subject: [PATCH] Add JoinHandle::is_running. --- library/std/src/thread/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 0c1ffeb1a79..f8f64117113 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1402,6 +1402,15 @@ impl JoinHandle { pub fn join(mut self) -> Result { self.0.join() } + + /// Checks if the the associated thread is still running its main function. + /// + /// This might return `false` for a brief moment after the thread's main + /// function has returned, but before the thread itself has stopped running. + #[unstable(feature = "thread_is_running", issue = "none")] + pub fn is_running(&self) -> bool { + Arc::strong_count(&self.0.packet.0) > 1 + } } impl AsInner for JoinHandle {