Struct std::thread::JoinHandle
A handle that allows to wait for the thread to finish.
Each JoinHandle
must be either joined or detached before it goes out of scope.
Failure to do so will result in a resource leak.
Methods
impl JoinHandle<T> { ... }
-
fn thread(self: &JoinHandle<T>) -> Thread
Returns the Thread object associated with this join handle.
-
fn join(self: &mut JoinHandle<T>) -> Result<T, JoinError>
Waits for the associated thread to finish.
Returns the return value of the thread function if the thread ran to completion. It it panicked or was killed, it returns an error variant of
JoinError
.Joining a thread that has already been joined or detached is undefined behavior.
-
fn detach(self: &mut JoinHandle<T>)
Detaches the thread, letting it run in background.
After the thread finishes, the resources associated with it will be freed automatically. If a detached thread panics, the process will terminate.
Detaching a thread that has already been joined or detached is undefined behavior.