A thread is an independently scheduled execution path that can run at the same time as other threads. Rust uses OS threads, which have separate stacks and local state, making them efficient and independent. section 11.6
Create a thread with std::thread::spawn and give it a closure describing its work. The result is a JoinHandle, which lets the main thread wait until the spawned thread finishes. section 11.6.1 section 11.7
Why joining matters
Spawning ten printing threads does not guarantee ten messages: the main thread may finish first and shut down the program. Keeping the process busy may give them time, but joining each thread is the reliable solution. Output order and timing can vary because the threads run independently. section 11.6.1
Keep these rules in mind when spawning work:
- Use JoinHandle::join when the program must wait for a thread. section 11.7
- Expect spawned closures and return values to meet Send and 'static lifetime requirements; move commonly transfers captured data into the thread. section 11.7
- Use scoped threads when work should borrow data without requiring the 'static lifetime, and ensure every scoped thread eventually ends. section 12.6











