Skip to content

Commit d718b1a

Browse files
committed
Add JoinHandle::is_running.
1 parent 58899c4 commit d718b1a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/std/src/thread/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,15 @@ impl<T> JoinHandle<T> {
14021402
pub fn join(mut self) -> Result<T> {
14031403
self.0.join()
14041404
}
1405+
1406+
/// Checks if the the associated thread is still running its main function.
1407+
///
1408+
/// This might return `false` for a brief moment after the thread's main
1409+
/// function has returned, but before the thread itself has stopped running.
1410+
#[unstable(feature = "thread_is_running", issue = "none")]
1411+
pub fn is_running(&self) -> bool {
1412+
Arc::strong_count(&self.0.packet.0) > 1
1413+
}
14051414
}
14061415

14071416
impl<T> AsInner<imp::Thread> for JoinHandle<T> {

0 commit comments

Comments
 (0)