Skip to content

Commit 5c0a1b6

Browse files
authored
Rollup merge of rust-lang#94549 - m-ou-se:thread-is-finished, r=yaahc
Rename JoinHandle::is_running to is_finished. This is renaming `is_running` to `is_finished` as discussed on the tracking issue here: rust-lang#90470 (comment) Taking some of the docs suggestions from rust-lang#94033
2 parents 4e3121c + af86b55 commit 5c0a1b6

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

library/std/src/thread/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1443,13 +1443,18 @@ impl<T> JoinHandle<T> {
14431443
self.0.join()
14441444
}
14451445

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

library/std/src/thread/scoped.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
240240
///
241241
/// ```
242242
/// #![feature(scoped_threads)]
243-
/// #![feature(thread_is_running)]
244243
///
245244
/// use std::thread;
246245
///
@@ -274,7 +273,6 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
274273
///
275274
/// ```
276275
/// #![feature(scoped_threads)]
277-
/// #![feature(thread_is_running)]
278276
///
279277
/// use std::thread;
280278
///
@@ -289,13 +287,18 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
289287
self.0.join()
290288
}
291289

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

library/std/src/thread/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn test_run_basic() {
5252
}
5353

5454
#[test]
55-
fn test_is_running() {
55+
fn test_is_finished() {
5656
let b = Arc::new(Barrier::new(2));
5757
let t = thread::spawn({
5858
let b = b.clone();
@@ -63,14 +63,14 @@ fn test_is_running() {
6363
});
6464

6565
// Thread is definitely running here, since it's still waiting for the barrier.
66-
assert_eq!(t.is_running(), true);
66+
assert_eq!(t.is_finished(), false);
6767

6868
// Unblock the barrier.
6969
b.wait();
7070

71-
// Now check that t.is_running() becomes false within a reasonable time.
71+
// Now check that t.is_finished() becomes true within a reasonable time.
7272
let start = Instant::now();
73-
while t.is_running() {
73+
while !t.is_finished() {
7474
assert!(start.elapsed() < Duration::from_secs(2));
7575
thread::sleep(Duration::from_millis(15));
7676
}

0 commit comments

Comments
 (0)