Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/thread"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
mem |
core/mem |
thread.dodo |
native |
std/thread/native |
thread.dodo |
ptr |
core/ptr |
thread.dodo |
Unit
Struct · Source
pub struct Unit {
}
ErrorKind
Enum · Source
pub enum ErrorKind {
StartFailed
AllocationFailed
InvalidLayout
}
ThreadError
Struct · Source
pub struct ThreadError {
pub kind: ErrorKind
pub native_code: i32
}
Storage
Struct · Source
Stable caller-owned storage. A Join exclusively borrows the complete storage until the worker has stopped; moving, destroying or reusing it is rejected. T is a move task with a statically dispatched run(self)->R method.
pub struct Storage<T, R> {
// Private implementation fields omitted.
}
Storage.new
Function · Source
pub fn new() -> Storage<T, R>
Join
Struct · Source
pub struct Join<T, R> {
// Private implementation fields omitted.
}
Join.is_finished
Function · Source
pub fn is_finished(&self) -> bool
Join.join
Function · Source
Joining synchronizes all worker writes before transferring the result. Native failure indicates an unsafe contract violation and aborts; it cannot release caller storage while a worker might still access it.
pub fn join(self) -> R
spawn
Function · Source
Every supported normal exit joins, including return, ?, break, continue, and explicit drop. Dodo traps abort the process and do not unwind. Scoped borrowing inside tasks is intentionally unavailable: checking a caller storage borrow alone does not make captured references thread-safe.
pub fn spawn<T, R>(storage: &mut Storage<T, R>, task: T) -> Join<T, R>!ThreadError from(storage)
yield_now
Function · Source
pub fn yield_now()
sleep_ms
Function · Source
pub fn sleep_ms(milliseconds: u32)
NativeAllocator
Struct · Source
Explicit permission to allocate an independently owned native mapping. It neither installs nor consults a global Dodo allocator.
pub struct NativeAllocator {
}
NativeAllocator.new
Function · Source
pub fn new() -> NativeAllocator
OwnedJoin
Struct · Source
SAFETY: this unique owner may move between threads. Its constructors check both payloads, and the worker/owner disposition handshake releases mapping and result exactly once. No checked reference escapes its raw storage.
@unsafe_send
pub struct OwnedJoin<T, R> {
// Private implementation fields omitted.
}
OwnedJoin.is_finished
Function · Source
pub fn is_finished(&self) -> bool
OwnedJoin.join
Function · Source
pub fn join(self) -> R
OwnedJoin.detach
Function · Source
Detach explicitly gives up result access. The task continues, destroys its result when complete and releases its own mapping. Process exit does not wait for detached workers. There is no forcible cancellation.
pub fn detach(self)
spawn_owned
Function · Source
pub fn spawn_owned<T, R>(allocator: &NativeAllocator, task: T) -> OwnedJoin<T, R>!ThreadError