Struct otter::prelude::thread::JoinHandle 1.0.0[−][src]
pub struct JoinHandle<T>(_);
Expand description
An owned permission to join on a thread (block on its termination).
A JoinHandle
detaches the associated thread when it is dropped, which
means that there is no longer any handle to thread and no way to join
on it.
Due to platform restrictions, it is not possible to Clone
this
handle: the ability to join a thread is a uniquely-owned permission.
This struct
is created by the thread::spawn
function and the
thread::Builder::spawn
method.
Examples
Creation from thread::spawn
:
use std::thread; let join_handle: thread::JoinHandle<_> = thread::spawn(|| { // some work here });
Creation from thread::Builder::spawn
:
use std::thread; let builder = thread::Builder::new(); let join_handle: thread::JoinHandle<_> = builder.spawn(|| { // some work here }).unwrap();
Child being detached and outliving its parent:
use std::thread; use std::time::Duration; let original_thread = thread::spawn(|| { let _detached_thread = thread::spawn(|| { // Here we sleep to make sure that the first thread returns before. thread::sleep(Duration::from_millis(10)); // This will be called, even though the JoinHandle is dropped. println!("♫ Still alive ♫"); }); }); original_thread.join().expect("The thread being joined has panicked"); println!("Original thread is joined."); // We make sure that the new thread has time to run, before the main // thread returns. thread::sleep(Duration::from_millis(1000));
Implementations
Extracts a handle to the underlying thread.
Examples
use std::thread; let builder = thread::Builder::new(); let join_handle: thread::JoinHandle<_> = builder.spawn(|| { // some work here }).unwrap(); let thread = join_handle.thread(); println!("thread id: {:?}", thread.id());
Waits for the associated thread to finish.
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 are ordered before all
operations that happen after join
returns.
If the child thread panics, Err
is returned with the parameter given
to panic!
.
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 std::thread; let builder = thread::Builder::new(); let join_handle: thread::JoinHandle<_> = builder.spawn(|| { // some work here }).unwrap(); join_handle.join().expect("Couldn't join on the associated thread");
Trait Implementations
Extracts the raw pthread_t without taking ownership
Consumes the thread, returning the raw pthread_t Read more
Auto Trait Implementations
impl<T> !RefUnwindSafe for JoinHandle<T>
impl<T> Unpin for JoinHandle<T>
impl<T> !UnwindSafe for JoinHandle<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
[src]
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
[src]Use this to cast from one trait object type to another. Read more
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
[src]
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
[src]Use this to upcast a trait to one of its supertraits. Read more
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
F: ?Sized,
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
[src]
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
F: ?Sized,
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
[src]pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
[src]
pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
[src]Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V