diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2022-01-04 14:52:55 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2022-01-04 15:15:41 +0100 |
| commit | cc699e1b62573fef34e2521a6ada0975e79b0459 (patch) | |
| tree | 873e99826168a1fd626b981cad4d630b51d58af9 /library/std/src/thread | |
| parent | 0e24ad537be4d47686f3b9e3e6623664bce7cbc2 (diff) | |
| download | rust-cc699e1b62573fef34e2521a6ada0975e79b0459.tar.gz rust-cc699e1b62573fef34e2521a6ada0975e79b0459.zip | |
Add ScopedJoinHandle::is_running().
Diffstat (limited to 'library/std/src/thread')
| -rw-r--r-- | library/std/src/thread/scoped.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/library/std/src/thread/scoped.rs b/library/std/src/thread/scoped.rs index 8e9a43e05be..0b65c682c56 100644 --- a/library/std/src/thread/scoped.rs +++ b/library/std/src/thread/scoped.rs @@ -5,7 +5,7 @@ use crate::io; use crate::marker::PhantomData; use crate::panic::{catch_unwind, resume_unwind, AssertUnwindSafe}; use crate::sync::atomic::{AtomicUsize, Ordering}; -use crate::sync::Mutex; +use crate::sync::{Arc, Mutex}; /// TODO: documentation pub struct Scope<'env> { @@ -114,6 +114,15 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> { pub fn thread(&self) -> &Thread { &self.0.thread } + + /// 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 = "90470")] + pub fn is_running(&self) -> bool { + Arc::strong_count(&self.0.packet) > 1 + } } impl<'env> fmt::Debug for Scope<'env> { |
