std-method
JoinHandle::join: wait and synchronize
Joining waits for completion and returns either the worker result or its panic payload. Completion synchronizes with the successful return from the join operation. It does not impose an ordering between different workers before they finish. Expected stdout (not executed): 10 20 Common mistake: Expecting the first spawned worker to finish first.
Formal Syntax & Structure
rust syntaxrust
handle.join() -> thread::Result<T>Working Example
Example Snippetrust
fn main() { let a = std::thread::spawn(|| 10); let b = std::thread::spawn(|| 20); println!("{} {}", a.join().unwrap(), b.join().unwrap());}