pub struct JoinHandle<T>(_);
An owned permission to join on a thread (block on its termination).
A JoinHandle detaches the child thread when it is dropped.
Due to platform restrictions, it is not possible to Clone this handle: the ability to join a child thread is a uniquely-owned permission.
This struct is created by the thread::spawn function and the thread::Builder::spawn method.
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(); impl<T> JoinHandle<T>
[src]
fn thread(&self) -> &ThreadExtracts a handle to the underlying thread.
#![feature(thread_id)]
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()); fn join(self) -> Result<T>Waits for the associated thread to finish.
If the child thread panics, Err is returned with the parameter given to panic.
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"); impl<T> Debug for JoinHandle<T>
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter.
impl<T> JoinHandleExt for JoinHandle<T>
fn as_pthread_t(&self) -> RawPthreadExtracts the raw pthread_t without taking ownership
fn into_pthread_t(self) -> RawPthreadConsumes the thread, returning the raw pthread_t Read more
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/thread/struct.JoinHandle.html