simple multithreaded hello world
use std::thread;
use std::time::Duration;
fn main() {
// Create a new thread
let handle = thread::spawn(|| {
for i in 1..10 {
println!("Hello World! {}. Printing from spawned thread", i);
thread:: sleep(Duration::from_millis(1));
}
});
// Main thread
for i in 1..10 {
println!("Hello World! {} from the main thread", i);
thread::sleep(Duration::from_millis(2));
}
// Hold the main thread until the spawned thread has completed
handle.join().unwrap();
}