use std::thread;
use std::time::Duration;

fn main() {
    let mut handles = Vec::new();
    for i in 0..10{
        handles.push(
            thread::spawn(move || {
                println!("create thread {}", i);
                thread::sleep(Duration::from_millis(1000));
                println!("thread {} is complete", i);
            })
        );
    }

    let mut completed_threads = 0;
    for handle in handles {
        handle.join().unwrap();
        completed_threads += 1;
    }

    if completed_threads != 10 {
        panic!("All threads did not finish!");
    }
}
