ThreadError
pub enum ThreadError = { OutOfMemory, CreateFailed, JoinFailed, DetachFailed, AlreadyJoined }Variants
OutOfMemoryCreateFailedJoinFailedDetachFailedAlreadyJoined
pub enum ThreadError = { OutOfMemory, CreateFailed, JoinFailed, DetachFailed, AlreadyJoined }OutOfMemoryCreateFailedJoinFailedDetachFailedAlreadyJoinedfn alloc_in[A: allocators.GeneralAllocator](ac: A, size: usize) option[ref void]fn free_in[A: allocators.GeneralAllocator](ac: A, ptr: ref void) voidpub type Thread = { handle: ref void, joined: bool }Opaque thread handle — wraps pthread_t on POSIX, HANDLE on Windows.
| Name | Type |
|---|---|
handle | ref void |
joined | bool |
extern (C, header) fn CreateThread(lpThreadAttributes: ref void, dwStackSize: usize, lpStartAddress: usize, lpParameter: ref void, dwCreationFlags: u32, lpThreadId: ref u32) ref void = trust { ... } = "CreateThread"extern (C, header) fn WaitForSingleObject(hHandle: ref void, dwMilliseconds: u32) u32 = trust { ... } = "WaitForSingleObject"extern (C, header) fn CloseHandle(hObject: ref void) i32 = trust { ... } = "CloseHandle"extern (C, header) fn GetCurrentThreadId() u32 = trust { ... } = "GetCurrentThreadId"extern (C, header) fn SwitchToThread() i32 = trust { ... } = "SwitchToThread"pub fn (Thread) new[A: allocators.GeneralAllocator](ac: A, entry: fn(ref void) ref void, arg: ref void) result[ref void, ThreadError]Create a new thread running entry with the given arg.
pub fn (Thread) join[A: allocators.GeneralAllocator](ac: A, thread: Thread) result[ref void, ThreadError]Join a thread, blocking until it completes. Returns the thread's return value, or an error if the thread cannot be joined.
A thread can only be joined once. Subsequent calls will return AlreadyJoined.
pub fn (Thread) detach[A: allocators.GeneralAllocator](ac: A, thread: Thread) result[void, ThreadError]Detach a thread, allowing it to run independently. Detached threads automatically release resources when they complete. Returns an error if detachment fails.
pub fn (Thread) free[A: allocators.GeneralAllocator](ac: A, thread: mut Thread) voidFree a thread handle after it has been joined or detached.
pub fn current_thread_id() usizeGet the current thread's ID. Returns a platform-specific thread identifier.
pub fn yield_thread() void = trust { ... }Yield the current thread's remaining time slice to allow other threads to run.
pub type Mutex = { ptr: ref void }A simple mutex using platform-specific primitives.
On POSIX, this uses pthread_mutex_t (40 bytes on most systems). On Windows, it uses CRITICAL_SECTION (48 bytes on most systems).
| Name | Type |
|---|---|
ptr | ref void |
extern (C, header) fn InitializeCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "InitializeCriticalSection"extern (C, header) fn DeleteCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "DeleteCriticalSection"extern (C, header) fn EnterCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "EnterCriticalSection"extern (C, header) fn LeaveCriticalSection(lpCriticalSection: ref void) void = trust { ... } = "LeaveCriticalSection"pub fn (Mutex) new[A: allocators.GeneralAllocator](ac: A) option[ref void]Create and initialize a new mutex. Returns the mutex handle or none on failure.
pub fn (Mutex) lock(m: Mutex) voidLock a mutex, blocking until it becomes available.
pub fn (Mutex) unlock(m: Mutex) void = trust { ... }Unlock a previously locked mutex.
pub fn (Mutex) free[A: allocators.GeneralAllocator](ac: A, m: mut Mutex) voidDestroy and free a mutex.
fn thread_test_entry(arg: ref void) ref void