Modules

Thread

moduleSource
macOSLinuxWindowsAndroid

#import "Thread";

Procedures#

General#

(thread: *Thread, proc: Thread_Proc, temporary_storage_size: s32 = 16384, starting_storage: *Temporary_Storage = null, name := "") -> bool

Prepares thread to run proc. Start it with thread_start. Returns false when proc is null, the storage size is negative or an allocation fails.

Synchronization#

init3 overloads
(m: *Mutex, desired_name := "", desired_order: Mutex_Order = -1)

Sets up a mutex. It is recursive: the thread that holds it can lock it again, and has to unlock it as many times.

(condition_variable: *Per_OS_Condition_Variable_Type, csection: *Per_OS_Critical_Section_Type, wait_time_ms: s32 = -1)
(condition_variable: *Per_OS_Condition_Variable_Type)

Waits on c until another thread calls wake or wake_all. It can return without either, so check the condition again afterwards.

(s: *Semaphore, milliseconds: s32 = -1) -> Wait_For_Result

Takes one count from the semaphore, waiting for signal if there is none. The result says whether it got one.

Lifecycle#

Types#

:: #type (group: *Thread_Group, thread: *Thread, work: *void) -> Thread_Continue_Status

Constants#

:: OS == .LINUX || OS == .MACOS || OS == .IOS || OS == .ANDROID
DEINIT_UNFINISHEDsince 0.31.0
:: "thread_deinit needs a thread that has finished: wait for it first with thread_is_done(*thread, -1), which blocks until it ends"

What thread_deinit says when the thread is still running or was never started.