How to Use the Handle Pattern for Resource Management

Use thread::spawn to start a thread and handle.join() to wait for its completion.

Use thread::spawn to create a thread and handle.join() to wait for it to finish, ensuring resources are managed safely.

use std::thread;

fn main() {
    let handle = thread::spawn(|| {
        println!("Working in the spawned thread");
    });

    handle.join().unwrap();
    println!("Thread finished");
}