How to use scoped threads

Rust lacks scoped threads; use std::thread::spawn with join to manage thread lifetimes manually.

Scoped threads are not a feature in Rust; use std::thread::spawn to create threads and .join() to wait for them to finish. This ensures the main thread blocks until the spawned thread completes, preventing the program from exiting prematurely.

use std::thread;

fn main() {
    let handle = thread::spawn(|| {
        println!("Running in a thread");
    });
    handle.join().unwrap();
    println!("Thread finished");
}