Struct ScopedJoinHandle

struct ScopedJoinHandle<'scope, T> { ... }

A handle that can be used to join its scoped thread.

This struct is created by the Scope::spawn method and the ScopedThreadBuilder::spawn method.

Implementations

impl<T> ScopedJoinHandle<'_, T>

fn join(self: Self) -> Result<T>

Waits for the thread to finish and returns its result.

If the child thread panics, an error is returned. Note that if panics are implemented by aborting the process, no error is returned; see the notes of [std::panic::catch_unwind].

Panics

This function may panic on some platforms if a thread attempts to join itself or otherwise may create a deadlock with joining threads.

Examples

use crossbeam_utils::thread;

thread::scope(|s| {
    let handle1 = s.spawn(|_| println!("I'm a happy thread :)"));
    let handle2 = s.spawn(|_| panic!("I'm a sad thread :("));

    // Join the first thread and verify that it succeeded.
    let res = handle1.join();
    assert!(res.is_ok());

    // Join the second thread and verify that it panicked.
    let res = handle2.join();
    assert!(res.is_err());
}).unwrap();
fn thread(self: &Self) -> &Thread

Returns a handle to the underlying thread.

Examples

use crossbeam_utils::thread;

thread::scope(|s| {
    let handle = s.spawn(|_| println!("A child thread is running"));
    println!("The child thread ID: {:?}", handle.thread().id());
}).unwrap();

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

impl<'scope, T> RefUnwindSafe 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> Debug for ScopedJoinHandle<'_, T>

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

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

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> JoinHandleExt for ScopedJoinHandle<'_, T>

fn as_pthread_t(self: &Self) -> RawPthread
fn into_pthread_t(self: Self) -> RawPthread

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

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

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>