Skip to content

Commit

Permalink
Rename JoinHandle::is_running to is_finished and update docs.
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
  • Loading branch information
m-ou-se and joshtriplett committed Mar 3, 2022
1 parent 2f8d1a8 commit dadf2ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions library/std/src/thread/mod.rs
Expand Up @@ -1443,13 +1443,18 @@ impl<T> JoinHandle<T> {
self.0.join()
}

/// Checks if the associated thread is still running its main function.
/// Checks if the associated thread has finished running its main function.
///
/// This might return `false` for a brief moment after the thread's main
/// This might return `true` for a brief moment after the thread's main
/// function has returned, but before the thread itself has stopped running.
/// However, once this returns `true`, [`join`][Self::join] can be expected
/// to return quickly, without blocking for any significant amount of time.
///
/// This function does not block. To block while waiting on the thread to finish,
/// use [`join`][Self::join].
#[unstable(feature = "thread_is_running", issue = "90470")]
pub fn is_running(&self) -> bool {
Arc::strong_count(&self.0.packet) > 1
pub fn is_finished(&self) -> bool {
Arc::strong_count(&self.0.packet) == 1
}
}

Expand Down
13 changes: 9 additions & 4 deletions library/std/src/thread/scoped.rs
Expand Up @@ -289,13 +289,18 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
self.0.join()
}

/// Checks if the associated thread is still running its main function.
/// Checks if the associated thread has finished running its main function.
///
/// This might return `false` for a brief moment after the thread's main
/// This might return `true` for a brief moment after the thread's main
/// function has returned, but before the thread itself has stopped running.
/// However, once this returns `true`, [`join`][Self::join] can be expected
/// to return quickly, without blocking for any significant amount of time.
///
/// This function does not block. To block while waiting on the thread to finish,
/// use [`join`][Self::join].
#[unstable(feature = "thread_is_running", issue = "90470")]
pub fn is_running(&self) -> bool {
Arc::strong_count(&self.0.packet) > 1
pub fn is_finished(&self) -> bool {
Arc::strong_count(&self.0.packet) == 1
}
}

Expand Down

0 comments on commit dadf2ad

Please sign in to comment.