Rust-Programming-Cookbook/Chapter05/sample_multiple_threads.rs

27 wiersze
627 B
Rust
Czysty Zwykły widok Historia

2017-07-31 06:59:18 +00:00
//-- #########################
//-- Task: Spawning multiple threads in rust
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 19 March 17
//-- #########################
use std::thread;
fn main() {
thread::spawn(move || {
println!("Hello from spawned thread");
});
let join_handle = thread::spawn(move || {
println!("Hello from second spawned thread");
17
});
println!("Hello from the main thread");
match join_handle.join() {
Ok(x) => println!("Second spawned thread returned {}", x),
Err(_) => println!("Second spawned thread panicked")
}
}