Struct crossbeam_utils::thread::ScopedJoinHandle[][src]

pub struct ScopedJoinHandle<'scope, T> { /* fields omitted */ }
Expand description

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>[src]

pub fn join(self) -> Result<T>[src]

Waits for the thread to finish and returns its result.

If the child thread panics, an error is returned.

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();

pub fn thread(&self) -> &Thread[src]

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();

Trait Implementations

impl<T> AsRawHandle for ScopedJoinHandle<'_, T>[src]

fn as_raw_handle(&self) -> RawHandle[src]

Extracts the raw handle, without taking any ownership.

impl<T> Debug for ScopedJoinHandle<'_, T>[src]

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

Formats the value using the given formatter. Read more

impl<T> IntoRawHandle for ScopedJoinHandle<'_, T>[src]

fn into_raw_handle(self) -> RawHandle[src]

Consumes this object, returning the raw underlying handle. Read more

impl<T> Send for ScopedJoinHandle<'_, T>[src]

impl<T> Sync for ScopedJoinHandle<'_, T>[src]

Auto Trait Implementations

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.