Add JoinHandle::is_running.

This commit is contained in:
Mara Bos 2021-10-31 15:02:38 +01:00
parent 58899c4d9c
commit d718b1a795
1 changed files with 9 additions and 0 deletions

View File

@ -1402,6 +1402,15 @@ impl<T> JoinHandle<T> {
pub fn join(mut self) -> Result<T> {
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<T> AsInner<imp::Thread> for JoinHandle<T> {