xur_

> 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

# sleep(millis: u64)

Pauses the current thread for millis milliseconds.

# spawn(f: fn() -> T) -> JoinHandle

Starts a new thread that calls f.

> types

┌ type JoinHandle

A running thread. Joining it gives the result of its function.

# join_handle.join() -> T

Waits 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());
}