Function origin_studio::std::thread::spawn
source · pub fn spawn<F>(f: F) -> JoinHandlewhere
F: FnOnce() + Send + 'static,Examples found in repository?
examples/rust-by-example-threads.rs (lines 16-18)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
// Make a vector to hold the children which are spawned.
let mut children = vec![];
for i in 0..NTHREADS {
// Spin up another thread
children.push(thread::spawn(move || {
println!("this is thread number {}", i);
}));
}
for child in children {
// Wait for the thread to finish. Returns a result.
let _ = child.join();
}
}