diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-10-31 15:02:38 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2021-10-31 15:09:36 +0100 |
| commit | d718b1a79508169f10cd4b691071d4308ac15fc3 (patch) | |
| tree | 9f60b7ce0033b74eb7385156bb27bc625f2a2ef6 /library/std/src/thread | |
| parent | 58899c4d9c63a6d27ac395ee9597ae797df7f026 (diff) | |
| download | rust-d718b1a79508169f10cd4b691071d4308ac15fc3.tar.gz rust-d718b1a79508169f10cd4b691071d4308ac15fc3.zip | |
Add JoinHandle::is_running.
Diffstat (limited to 'library/std/src/thread')
| -rw-r--r-- | library/std/src/thread/mod.rs | 9 |
1 files changed, 9 insertions, 0 deletions
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<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> { |
