use std::thread; use std::time::Duration; fn thread_function(name : &str){ for i in 1..20 { println!("{name}: i = {i}"); } } fn main(){ /* * Note: You can capture specific variables with a closure too * | variables | { closure expression } */ thread::spawn(|| {thread_function("SHODAN") }); thread::spawn(|| {thread_function("Skynet") }); thread::sleep(Duration::from_millis(1)); for i in 1..20 { println!("main: i = {i}"); } }