Thread module

thread_init

procedureSource

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.

Example↗
hello :: (thread: *Thread) -> s64 { return 0; }
thread: Thread;
assert(thread_init(*thread, hello, name = "hello"));
thread_start(*thread);
assert(thread_is_done(*thread, -1));
thread_deinit(*thread);
thread_init :: (
    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.

Parameters

thread: *Thread
set up by this call. It has to stay where it is until thread_deinit.
proc: Thread_Proc
runs on the new thread and is given thread.
temporary_storage_size: s32 = 16384
bytes of temporary storage for the thread. 0 gives it none.
starting_storage: *Temporary_Storage = null
storage to use instead of allocating temporary_storage_size bytes.
name := ""
for debuggers and tools that list threads.

Returns

bool
Example↗
hello :: (thread: *Thread) -> s64 { return 0; }
thread: Thread;
assert(thread_init(*thread, hello, name = "hello"));
thread_start(*thread);
assert(thread_is_done(*thread, -1));
thread_deinit(*thread);