// waiting for threads in rust // this example makes a single thread, but does not wait for it to end // so some of the actions of the thread are not done. use std::time::Duration; use std::thread; fn main() { main1(); } // this is the usual way to do it -- and really the only way fn main1() { // make a single thread using a no argument function defined right here // by rule the thing passed must be a "FnOnce closure". // FnOnce means that the function can be used at most once. // So the function cannot be pre-defined using 'fn xxx() ...' // Also by rule the function must take no args! thread::spawn(|| { // all this does is print and sleep 10 times for i in 1..10 { println!("hi number {} from the spawned thread!", i); //thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { println!("hi number {} from the main thread!", i); //thread::sleep(Duration::from_millis(1)); } }