Skip to content

Commit cc699e1

Browse files
committed
Add ScopedJoinHandle::is_running().
1 parent 0e24ad5 commit cc699e1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

library/std/src/thread/scoped.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::io;
55
use crate::marker::PhantomData;
66
use crate::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
77
use crate::sync::atomic::{AtomicUsize, Ordering};
8-
use crate::sync::Mutex;
8+
use crate::sync::{Arc, Mutex};
99

1010
/// TODO: documentation
1111
pub struct Scope<'env> {
@@ -114,6 +114,15 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
114114
pub fn thread(&self) -> &Thread {
115115
&self.0.thread
116116
}
117+
118+
/// Checks if the the associated thread is still running its main function.
119+
///
120+
/// This might return `false` for a brief moment after the thread's main
121+
/// function has returned, but before the thread itself has stopped running.
122+
#[unstable(feature = "thread_is_running", issue = "90470")]
123+
pub fn is_running(&self) -> bool {
124+
Arc::strong_count(&self.0.packet) > 1
125+
}
117126
}
118127

119128
impl<'env> fmt::Debug for Scope<'env> {

0 commit comments

Comments
 (0)