Struct ScopedJoinHandle

struct ScopedJoinHandle<'scope, T>(_)

An owned permission to join on a scoped thread (block on its termination).

See Scope::spawn for details.

Implementations

impl<'scope, T> ScopedJoinHandle<'scope, T>

fn thread(self: &Self) -> &Thread

Extracts a handle to the underlying thread.

Examples

use std::thread;

thread::scope(|s| {
    let t = s.spawn(|| {
        println!("hello");
    });
    println!("thread id: {:?}", t.thread().id());
});
fn join(self: Self) -> Result<T>

Waits for the associated thread to finish.

This function will return immediately if the associated thread has already finished. Otherwise, it fully waits for the thread to finish, including all destructors for thread-local variables that might be running after the main function of the thread.

In terms of atomic memory orderings, the completion of the associated thread synchronizes with this function returning. In other words, all operations performed by that thread happen before all operations that happen after join returns.

If the associated thread panics, Err is returned with the panic payload.

Examples

use std::thread;

thread::scope(|s| {
    let t = s.spawn(|| {
        panic!("oh no");
    });
    assert!(t.join().is_err());
});
fn is_finished(self: &Self) -> bool

Checks if the associated thread has finished running its main function.

is_finished supports implementing a non-blocking join operation, by checking is_finished, and calling join if it returns true. This function does not block. To block while waiting on the thread to finish, use [join][Self::join].

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.

impl<'scope, T> Debug for ScopedJoinHandle<'scope, T>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<'scope, T> Freeze for ScopedJoinHandle<'scope, T>

impl<'scope, T> RefUnwindSafe for ScopedJoinHandle<'scope, T>

impl<'scope, T> Send for ScopedJoinHandle<'scope, T>

impl<'scope, T> Sync for ScopedJoinHandle<'scope, T>

impl<'scope, T> Unpin for ScopedJoinHandle<'scope, T>

impl<'scope, T> UnsafeUnpin for ScopedJoinHandle<'scope, T>

impl<'scope, T> UnwindSafe for ScopedJoinHandle<'scope, T>

impl<T> Any for ScopedJoinHandle<'scope, T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ScopedJoinHandle<'scope, T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ScopedJoinHandle<'scope, T>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for ScopedJoinHandle<'scope, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for ScopedJoinHandle<'scope, T>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for ScopedJoinHandle<'scope, T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for ScopedJoinHandle<'scope, T>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>