> module
std::thread
running code in parallel
use std::thread; feature thread native only
std::thread spawns OS threads that run Xur functions and closures. A closure captures copies of the variables it uses, so share state through std::sync channels or a cell.
> functions
#
spawn(f: fn() -> T) -> JoinHandleStarts a new thread that calls f.
> types
A running thread. Joining it gives the result of its function.
#
join_handle.join() -> TWaits for the thread to finish and returns what f returned. If f stopped with a runtime error, so does join. Joining the same thread twice is a runtime error.
> examples
use std::thread;
use std::io;
fn main() {
let handle = thread::spawn(|| {
thread::sleep(100);
42
});
io::println("answer: {}", handle.join());
}