Thread
class Thread Import
Source: use thread::{Thread}; compiler/src/builtin_docs/thread.hy A handle to a function running on another OS thread, from spawn.
Pass it to join to wait for the result, or to detach to let the
thread finish on its own. A Thread cannot be sent to another thread.
Examples#
use thread::{spawn, join, Thread};
use tests::assert;
fn double(int n) -> int {
return n * 2;
}
fn main() {
let t: Thread = match spawn(double, 21) {
Result::Ok(t) => t,
Result::Err(_) => panic "spawn failed",
};
let n = match join(t) {
Result::Ok(n) => n,
Result::Err(_) => 0,
};
assert!(n == 42);
}
See also#
thread::spawnthread::jointhread::detachSender: The sending half of a channel made bychannel.Receiver: The receiving half of a channel made bychannel.Mutex: A mutual-exclusion lock that owns a value, made bymutex.RwLock: A readers-writer lock that owns a value, made byrwlock.