Thread
OS thread spawning and joining
Fields:
// No FieldsMethods:
pub fn spawn[T](f: FnOnce() T) JoinHandle[T];pub fn yield_now();Module: std.thread
Source: std/thread.zn
Usage Example
use std.thread;use std.sync;fn main() {let counter = Arc.new(Mutex.new(0));let p1 = counter.clone();let p2 = counter.clone();let t1 = Thread.spawn(fn() i32 {let guard = p1.get_mut().lock();*guard += 1;return *guard;});let t2 = Thread.spawn(fn() i32 {let guard = p2.get_mut().lock();*guard += 1;return *guard;});let j1 = t1.join();let j2 = t2.join();@println("thread 1: {}", j1);@println("thread 2: {}", j2);@println("counter: {}", (*counter.get()).into_inner());}
Thread
OS thread spawning and joining
Fields:
// No FieldsMethods:
pub fn spawn[T](f: FnOnce() T) JoinHandle[T];pub fn yield_now();JoinHandle[T]
Running thread handle, owns the result slot
Fields:
native: NativeThread,slot: *T,done: bool,Methods:
pub fn join(self) T;Interfaces:
core.ops : Drop