A structure representing an Alumina thread.
Fields
-
inner: &mut ThreadInfo
Methods
impl Thread { ... }
-
fn current() -> Thread
Returns the current thread
If the current thread is a foreign thread (e.g. not spawned using spawnor a main thread of a program with a non-Alumina entrypoint), this function will panic.
-
fn id(self: &Thread) -> pthread_t
Returns the native thread id of a thread.
-
Suspends the current thread until another thread calls unpark.
If the thread was unparked before the park function is called, this function will return immediately. It may also return spuriously, so care must be taken if it is used as a synchronization primitive.
The purpose of this function is to efficiently wait on a condition and can be more lightweight than a CondVar on some platforms.
This is the same mechanism as Rust's thread parking.
Example
use std::sync::{Atomic, Ordering}; use std::thread::{Thread, spawn, sleep}; use std::time::Duration; let flag: Atomic<bool> = Atomic::new(false); let parked = spawn(|&flag| { while !flag.load(Ordering::SeqCst) { Thread::park(); } println!("Hello from `parked`"); }); sleep(Duration::from_secs(1)); println!("Hello from `parked`"); flag.store(true, Ordering::SeqCst); parked.thread().unpark(); parked.join().unwrap();
Run this example -
fn park_timeout(timeout: Duration)
-
fn unpark(self: &Thread)
Mixins
impl Thread { ... }
-
-
Returns
false
if arguments are equal,true
otherwise