Thread module

init

procedure7 overloadsSource

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

init :: (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.

Parameters

m: *Mutex
desired_name := ""
a label for the mutex. Only kept in builds with DEBUG set.
desired_order: Mutex_Order = -1
a rank for the mutex. Only kept in builds with DEBUG set; nothing acts on it yet. -1 for none.
init :: (cv: *Condition_Variable, desired_name := "")

Sets up a condition variable.

Parameters

desired_name := ""
a label for the condition variable. Only kept in builds with DEBUG set.
init :: (s: *Semaphore, initial_value: s32 = 0)

Sets up a semaphore.

Parameters

initial_value: s32 = 0
how many wait_for calls succeed before anyone calls signal.
init :: (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.

Parameters

m: *Mutex
desired_name := ""
a label for the mutex. Only kept in builds with DEBUG set.
desired_order: Mutex_Order = -1
a rank for the mutex. Only kept in builds with DEBUG set; nothing acts on it yet. -1 for none.
Example↗
mutex: Mutex;
init(*mutex);
defer destroy(*mutex);
lock(*mutex);
lock(*mutex); // the same thread may lock again
unlock(*mutex);
unlock(*mutex);
init :: (cv: *Condition_Variable, desired_name := "")

Sets up a condition variable.

Parameters

desired_name := ""
a label for the condition variable. Only kept in builds with DEBUG set.
Example↗
ready: Condition_Variable;
init(*ready);
defer destroy(*ready);
init :: (s: *Semaphore, initial_value: s32 = 0)

Sets up a semaphore.

Parameters

initial_value: s32 = 0
how many wait_for calls succeed before anyone calls signal.
Example↗
semaphore: Semaphore;
init(*semaphore, 1);
defer destroy(*semaphore);
assert(wait_for(*semaphore, 0) == .SUCCESS);
assert(wait_for(*semaphore, 0) == .TIMEOUT);
init :: (
    group: *Thread_Group,
    num_threads: s32,
    group_proc: Thread_Group_Proc,
    enable_work_stealing := false,
    temporary_storage_size: s32 = 16384,
    group_name := ""
)

Sets up group with num_threads worker threads that call group_proc for each piece of work. The workers are created but do not run until start.

Parameters

group: *Thread_Group
num_threads: s32
group_proc: Thread_Group_Proc
enable_work_stealing := false
lets an idle worker take work queued for another.
temporary_storage_size: s32 = 16384
bytes of temporary storage for each worker.
group_name := ""
used in log messages.

See also