Code Snippets

use std::thread;

fn main() {
    let handles: Vec<_> = (0..4).map(|i| {
        thread::spawn(move || {
            println!("worker {i}");
            i * 2
        })
    }).collect();

    for h in handles {
        println!("result = {}", h.join().unwrap());
    }
}