crossbeam::thread

Struct ScopedJoinHandle

Source
pub struct ScopedJoinHandle<'scope, T> { /* private fields */ }
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§

Source§

impl<T> ScopedJoinHandle<'_, T>

Source

pub fn join(self) -> Result<T, Box<dyn Any + Send>>

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

pub fn thread(&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();

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

fn as_pthread_t(&self) -> u64

Extracts the raw pthread_t without taking ownership
Source§

fn into_pthread_t(self) -> u64

Consumes the thread, returning the raw pthread_t Read more
Source§

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

Source§

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

Auto Trait Implementations§

§

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> UnwindSafe for ScopedJoinHandle<'scope, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.