Module
Module documentation.
modulethread
Classes
Classes and inheritance.
classthread::JoinHandle
@brief`JoinHandle` type.
@details`JoinHandle` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class JoinHandle {
/*
@brief `h` field.classthread::Builder
@brief`Builder` type.
@details`Builder` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class Builder {
/*
@brief `name` field.classthread::CancelToken
@brief`CancelToken` type.
@details`CancelToken` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class CancelToken {
/*
@brief `flag` field.classthread::ThreadLocal<T>
@brief`ThreadLocal` type.
@details`ThreadLocal` encapsulates state and operations exported by the system module. It commonly stores runtime handles, protocol state, buffers, configuration, or collection data. Its methods define the primary behavior for the type. If the type owns external resources, prefer `dispose` or `close` for deterministic release.
class ThreadLocal<T> {
/*
@brief `h` field.Functions
Free functions and class methods.
functionthread::__thread_spawn_ex
Signature
extern func __thread_spawn_ex(f: (Any) -> Int, arg: Any, name: String, stack_size_kb: Int, detached: Int) -> Int;extern func __thread_spawn_ex(f: (Any) -> Int, arg: Any, name: String, stack_size_kb: Int, detached: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_join_handle`.@briefBinds the low-level runtime symbol `__thread_spawn_ex`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- fFuture, callback, file handle, or function object that the operation observes or invokes.
- argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
- nameName.
- stack_size_kbSize or length value that limits how much data the operation processes.
- detachedWhether the thread or resource runs detached from join management.
@returnReturns the operation result as `Int`.
functionthread::__thread_join_handle
Signature
extern func __thread_join_handle(h: Int) -> Int;extern func __thread_join_handle(h: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_last_result`.@briefBinds the low-level runtime symbol `__thread_join_handle`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- hUnderlying runtime handle.
@returnReturns the operation result as `Int`.
functionthread::__thread_last_result
Signature
extern func __thread_last_result() -> Int;extern func __thread_last_result() -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_detach`.@briefBinds the low-level runtime symbol `__thread_last_result`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@returnReturns the operation result as `Int`.
functionthread::__thread_detach
Signature
extern func __thread_detach(h: Int) -> Int;extern func __thread_detach(h: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_sleep_ms`.@briefBinds the low-level runtime symbol `__thread_detach`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- hUnderlying runtime handle.
@returnReturns the operation result as `Int`.
functionthread::__thread_sleep_ms
Signature
extern func __thread_sleep_ms(ms: Int) -> Void;extern func __thread_sleep_ms(ms: Int) -> Void;
/*
@brief Binds the low-level runtime symbol `__thread_yield_now`.@briefBinds the low-level runtime symbol `__thread_sleep_ms`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- msDuration in milliseconds used for sleeping, waiting, or timeout calculation.
@returnVoid
functionthread::__thread_yield_now
Signature
extern func __thread_yield_now() -> Void;extern func __thread_yield_now() -> Void;
/*
@brief Binds the low-level runtime symbol `__thread_current_id`.@briefBinds the low-level runtime symbol `__thread_yield_now`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@returnVoid
functionthread::__thread_current_id
Signature
extern func __thread_current_id() -> Int;extern func __thread_current_id() -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_hardware_parallelism`.@briefBinds the low-level runtime symbol `__thread_current_id`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@returnReturns the operation result as `Int`.
functionthread::__thread_hardware_parallelism
Signature
extern func __thread_hardware_parallelism() -> Int;extern func __thread_hardware_parallelism() -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_local_new`.@briefBinds the low-level runtime symbol `__thread_hardware_parallelism`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@returnReturns the operation result as `Int`.
functionthread::__thread_local_new
Signature
extern func __thread_local_new() -> Int;extern func __thread_local_new() -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_local_free`.@briefBinds the low-level runtime symbol `__thread_local_new`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@returnReturns the operation result as `Int`.
functionthread::__thread_local_free
Signature
extern func __thread_local_free(h: Int) -> Void;extern func __thread_local_free(h: Int) -> Void;
/*
@brief Binds the low-level runtime symbol `__thread_local_has`.@briefBinds the low-level runtime symbol `__thread_local_free`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- hUnderlying runtime handle.
@returnVoid
functionthread::__thread_local_has
Signature
extern func __thread_local_has(h: Int) -> Int;extern func __thread_local_has(h: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_local_get`.@briefBinds the low-level runtime symbol `__thread_local_has`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- hUnderlying runtime handle.
@returnReturns the operation result as `Int`.
functionthread::__thread_local_get
Signature
extern func __thread_local_get(h: Int) -> Any;extern func __thread_local_get(h: Int) -> Any;
/*
@brief Binds the low-level runtime symbol `__thread_local_set`.@briefBinds the low-level runtime symbol `__thread_local_get`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- hUnderlying runtime handle.
@returnReturns the operation result as `Any`.
functionthread::__thread_local_set
Signature
extern func __thread_local_set(h: Int, value: Any) -> Int;extern func __thread_local_set(h: Int, value: Any) -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_park`.@briefBinds the low-level runtime symbol `__thread_local_set`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- hUnderlying runtime handle.
- valueValue to write or store.
@returnReturns the operation result as `Int`.
functionthread::__thread_park
Signature
extern func __thread_park() -> Int;extern func __thread_park() -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_park_timeout_ms`.@briefBinds the low-level runtime symbol `__thread_park`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@returnReturns the operation result as `Int`.
functionthread::__thread_park_timeout_ms
Signature
extern func __thread_park_timeout_ms(timeout_ms: Int) -> Int;extern func __thread_park_timeout_ms(timeout_ms: Int) -> Int;
/*
@brief Binds the low-level runtime symbol `__thread_unpark`.@briefBinds the low-level runtime symbol `__thread_park_timeout_ms`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns the operation result as `Int`.
functionthread::__thread_unpark
Signature
extern func __thread_unpark(thread_id: Int) -> Int;extern func __thread_unpark(thread_id: Int) -> Int;
/*@briefBinds the low-level runtime symbol `__thread_unpark`.
@detailsThis function is an external entry point used by system modules to access native runtime capabilities such as filesystem, networking, threading, GC, cryptography, or platform operations. Prefer the safe wrapper functions in the same file when available. When calling this entry directly, pass validated arguments that match the signature and handle failures according to the return-value convention.
@param
- thread_idNative thread identifier targeted or returned by the operation.
@returnReturns the operation result as `Int`.
functionthread::JoinHandle.init
Signature
func init(self: thread.JoinHandle, h: Int = 0) -> Void func init(self: thread.JoinHandle, h: Int = 0) -> Void {
self.h = h;
self.active = h != 0;@briefInitializes a `JoinHandle` instance.
@detailsEstablishes the initial field state for `JoinHandle` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- hUnderlying runtime handle.
@returnVoid
functionthread::JoinHandle.is_active
Signature
func is_active(self: thread.JoinHandle) -> Bool func is_active(self: thread.JoinHandle) -> Bool {
return self.active && self.h != 0;
}@briefTests whether the state satisfies the condition represented by `JoinHandle.is_active`.
@detailsExecutes the `is_active` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns a boolean result; true means the condition holds or the operation succeeded.
functionthread::JoinHandle.transfer
Signature
func transfer(self: thread.JoinHandle) -> thread.JoinHandle func transfer(self: thread.JoinHandle) -> thread.JoinHandle {
if !self.is_active() {
return new thread.JoinHandle();@briefProvides the system library operation `JoinHandle.transfer`.
@detailsExecutes the `transfer` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns the operation result as `thread.JoinHandle`.
functionthread::JoinHandle.join
Signature
func join(self: thread.JoinHandle) -> Int, ErrCode func join(self: thread.JoinHandle) -> Int, ErrCode {
if !self.is_active() {
return 0, std.ERR_INVALID;@briefProvides the system library operation `JoinHandle.join`.
@detailsExecutes the `join` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::JoinHandle.detach
Signature
func detach(self: thread.JoinHandle) -> ErrCode func detach(self: thread.JoinHandle) -> ErrCode {
if !self.is_active() {
return std.ERR_INVALID;@briefProvides the system library operation `JoinHandle.detach`.
@detailsExecutes the `detach` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::JoinHandle.dispose
Signature
func dispose(self: thread.JoinHandle) -> Void func dispose(self: thread.JoinHandle) -> Void {
if self.is_active() {
_ = self.detach();@briefExplicitly releases resources owned by `JoinHandle`.
@detailsThis method deterministically cleans up file descriptors, network connections, native handles, buffers, or other external resources. Implementations should be idempotent where possible, and repeated calls must not corrupt object state.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::JoinHandle.deinit
Signature
func deinit(self: thread.JoinHandle) -> Void func deinit(self: thread.JoinHandle) -> Void {
if self.is_active() {
_ = self.detach();@briefReleases fallback resources at the end of the `JoinHandle` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::Builder.init
Signature
func init(self: thread.Builder) -> Void func init(self: thread.Builder) -> Void {
self.name = "";
self.stack_size_kb = 0;@briefInitializes a `Builder` instance.
@detailsEstablishes the initial field state for `Builder` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::Builder.set_name
Signature
func set_name(self: thread.Builder, name: String) -> thread.Builder func set_name(self: thread.Builder, name: String) -> thread.Builder {
self.name = name;
return self;@briefSets state or configuration with `Builder.set_name`.
@detailsExecutes the `set_name` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- nameName.
@returnReturns the operation result as `thread.Builder`.
functionthread::Builder.set_stack_size_kb
Signature
func set_stack_size_kb(self: thread.Builder, stack_size_kb: Int) -> thread.Builder func set_stack_size_kb(self: thread.Builder, stack_size_kb: Int) -> thread.Builder {
self.stack_size_kb = stack_size_kb;
return self;@briefSets state or configuration with `Builder.set_stack_size_kb`.
@detailsExecutes the `set_stack_size_kb` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- stack_size_kbSize or length value that limits how much data the operation processes.
@returnReturns the operation result as `thread.Builder`.
functionthread::Builder.set_detached
Signature
func set_detached(self: thread.Builder, detached: Bool) -> thread.Builder func set_detached(self: thread.Builder, detached: Bool) -> thread.Builder {
self.detached = detached;
return self;@briefSets state or configuration with `Builder.set_detached`.
@detailsExecutes the `set_detached` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- detachedWhether the thread or resource runs detached from join management.
@returnReturns the operation result as `thread.Builder`.
functionthread::Builder.spawn
Signature
func spawn(self: thread.Builder, f: (Any) -> Int, arg: Any) -> thread.JoinHandle, ErrCode func spawn(self: thread.Builder, f: (Any) -> Int, arg: Any) -> thread.JoinHandle, ErrCode {
let detached_flag: Int = 0;
if self.detached {@briefProvides the system library operation `Builder.spawn`.
@detailsExecutes the `spawn` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- fFuture, callback, file handle, or function object that the operation observes or invokes.
- argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
@returnReturns `thread.JoinHandle, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::Builder.spawn_detached
Signature
func spawn_detached(self: thread.Builder, f: (Any) -> Int, arg: Any) -> ErrCode func spawn_detached(self: thread.Builder, f: (Any) -> Int, arg: Any) -> ErrCode {
let h: Int = __thread_spawn_ex(f, arg, self.name, self.stack_size_kb, 1);
if h == 0 {@briefProvides the system library operation `Builder.spawn_detached`.
@detailsExecutes the `spawn_detached` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- fFuture, callback, file handle, or function object that the operation observes or invokes.
- argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::Builder.deinit
Signature
func deinit(self: thread.Builder) -> Void func deinit(self: thread.Builder) -> Void {
}
}@briefReleases fallback resources at the end of the `Builder` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::CancelToken.init
Signature
func init(self: thread.CancelToken) -> Void func init(self: thread.CancelToken) -> Void {
self.flag = new sync.Int64(0);
self.released = false;@briefInitializes a `CancelToken` instance.
@detailsEstablishes the initial field state for `CancelToken` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::CancelToken.cancel
Signature
func cancel(self: thread.CancelToken) -> Void func cancel(self: thread.CancelToken) -> Void {
_ = self.flag.store(1);
}@briefProvides the system library operation `CancelToken.cancel`.
@detailsExecutes the `cancel` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::CancelToken.is_cancelled
Signature
func is_cancelled(self: thread.CancelToken) -> Bool func is_cancelled(self: thread.CancelToken) -> Bool {
return self.flag.load() != 0;
}@briefTests whether the state satisfies the condition represented by `CancelToken.is_cancelled`.
@detailsExecutes the `is_cancelled` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns a boolean result; true means the condition holds or the operation succeeded.
functionthread::CancelToken.reset
Signature
func reset(self: thread.CancelToken) -> Void func reset(self: thread.CancelToken) -> Void {
_ = self.flag.store(0);
}@briefProvides the system library operation `CancelToken.reset`.
@detailsExecutes the `reset` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::CancelToken.dispose
Signature
func dispose(self: thread.CancelToken) -> Void func dispose(self: thread.CancelToken) -> Void {
if !self.released {
dispose self.flag;@briefExplicitly releases resources owned by `CancelToken`.
@detailsThis method deterministically cleans up file descriptors, network connections, native handles, buffers, or other external resources. Implementations should be idempotent where possible, and repeated calls must not corrupt object state.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::CancelToken.deinit
Signature
func deinit(self: thread.CancelToken) -> Void func deinit(self: thread.CancelToken) -> Void {
if !self.released {
dispose self.flag;@briefReleases fallback resources at the end of the `CancelToken` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::ThreadLocal<T>.init
Signature
func init(self: thread.ThreadLocal<T>, default_value: T) -> Void func init(self: thread.ThreadLocal<T>, default_value: T) -> Void {
self.h = __thread_local_new();
self.default_value = default_value;@briefInitializes a `ThreadLocal` instance.
@detailsEstablishes the initial field state for `ThreadLocal` so other methods can be called safely. Constructor logic should keep fields consistent and avoid leaking partially initialized resources.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- default_valueValue supplied by the caller for storage, comparison, or encoding.
@returnVoid
functionthread::ThreadLocal<T>.has
Signature
func has(self: thread.ThreadLocal<T>) -> Bool func has(self: thread.ThreadLocal<T>) -> Bool {
if self.h == 0 {
return false;@briefProvides the system library operation `ThreadLocal.has`.
@detailsExecutes the `has` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns a boolean result; true means the condition holds or the operation succeeded.
functionthread::ThreadLocal<T>.get
Signature
func get(self: thread.ThreadLocal<T>) -> T func get(self: thread.ThreadLocal<T>) -> T {
if self.has() {
return __thread_local_get(self.h) => T;@briefReads the element for `ThreadLocal.get`.
@detailsExecutes the `get` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnReturns the operation result as `T`.
functionthread::ThreadLocal<T>.get_or
Signature
func get_or(self: thread.ThreadLocal<T>, default_value: T) -> T func get_or(self: thread.ThreadLocal<T>, default_value: T) -> T {
if self.has() {
return __thread_local_get(self.h) => T;@briefReads the state or data for `ThreadLocal.get_or`.
@detailsExecutes the `get_or` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- default_valueValue supplied by the caller for storage, comparison, or encoding.
@returnReturns the operation result as `T`.
functionthread::ThreadLocal<T>.set
Signature
func set(self: thread.ThreadLocal<T>, value: T) -> ErrCode func set(self: thread.ThreadLocal<T>, value: T) -> ErrCode {
if self.h == 0 {
return std.ERR_INVALID;@briefSets an element with `ThreadLocal.set`.
@detailsExecutes the `set` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
- valueValue to write or store.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::ThreadLocal<T>.dispose
Signature
func dispose(self: thread.ThreadLocal<T>) -> Void func dispose(self: thread.ThreadLocal<T>) -> Void {
if self.h != 0 {
_ = __thread_local_free(self.h);@briefExplicitly releases resources owned by `ThreadLocal`.
@detailsThis method deterministically cleans up file descriptors, network connections, native handles, buffers, or other external resources. Implementations should be idempotent where possible, and repeated calls must not corrupt object state.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::ThreadLocal<T>.deinit
Signature
func deinit(self: thread.ThreadLocal<T>) -> Void func deinit(self: thread.ThreadLocal<T>) -> Void {
if self.h != 0 {
_ = __thread_local_free(self.h);@briefReleases fallback resources at the end of the `ThreadLocal` lifetime.
@detailsThis destructor hook is called by object lifetime management to clean up underlying resources that were not released explicitly. Normal application code should prefer `dispose`, `close`, or the module-specific close function to release resources at a deterministic time.
@param
- selfThe current instance whose fields, handles, buffers, or external resources are read or modified by this method.
@returnVoid
functionthread::spawn
Signature
func spawn(f: (Any) -> Int, arg: Any) -> thread.JoinHandle, ErrCodefunc spawn(f: (Any) -> Int, arg: Any) -> thread.JoinHandle, ErrCode {
let h: Int = __thread_spawn_ex(f, arg, "", 0, 0);
if h == 0 {@briefProvides the system library operation `spawn`.
@detailsExecutes the `spawn` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- fFuture, callback, file handle, or function object that the operation observes or invokes.
- argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
@returnReturns `thread.JoinHandle, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::spawn_detached
Signature
func spawn_detached(f: (Any) -> Int, arg: Any) -> ErrCodefunc spawn_detached(f: (Any) -> Int, arg: Any) -> ErrCode {
let h: Int = __thread_spawn_ex(f, arg, "", 0, 1);
if h == 0 {@briefProvides the system library operation `spawn_detached`.
@detailsExecutes the `spawn_detached` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- fFuture, callback, file handle, or function object that the operation observes or invokes.
- argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::join
Signature
func join(handle: thread.JoinHandle) -> Int, ErrCodefunc join(handle: thread.JoinHandle) -> Int, ErrCode {
return handle.join();
}@briefProvides the system library operation `join`.
@detailsExecutes the `join` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- handleUnderlying runtime handle.
@returnReturns `Int, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::detach
Signature
func detach(handle: thread.JoinHandle) -> ErrCodefunc detach(handle: thread.JoinHandle) -> ErrCode {
return handle.detach();
}@briefProvides the system library operation `detach`.
@detailsExecutes the `detach` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- handleUnderlying runtime handle.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::sleep_ms
Signature
func sleep_ms(ms: Int) -> Voidfunc sleep_ms(ms: Int) -> Void {
_ = __thread_sleep_ms(ms);
}@briefProvides the system library operation `sleep_ms`.
@detailsExecutes the `sleep_ms` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- msDuration in milliseconds used for sleeping, waiting, or timeout calculation.
@returnVoid
functionthread::yield_now
Signature
func yield_now() -> Voidfunc yield_now() -> Void {
_ = __thread_yield_now();
}@briefProvides the system library operation `yield_now`.
@detailsExecutes the `yield_now` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@returnVoid
functionthread::current_id
Signature
func current_id() -> Intfunc current_id() -> Int {
return __thread_current_id();
}@briefProvides the system library operation `current_id`.
@detailsExecutes the `current_id` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@returnReturns the operation result as `Int`.
functionthread::hardware_parallelism
Signature
func hardware_parallelism() -> Intfunc hardware_parallelism() -> Int {
return __thread_hardware_parallelism();
}@briefProvides the system library operation `hardware_parallelism`.
@detailsExecutes the `hardware_parallelism` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@returnReturns the operation result as `Int`.
functionthread::park
Signature
func park() -> ErrCodefunc park() -> ErrCode {
return err_from_rc(__thread_park());
}@briefProvides the system library operation `park`.
@detailsExecutes the `park` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::park_timeout_ms
Signature
func park_timeout_ms(timeout_ms: Int) -> Bool, ErrCodefunc park_timeout_ms(timeout_ms: Int) -> Bool, ErrCode {
let rc: Int = __thread_park_timeout_ms(timeout_ms);
if rc < 0 {@briefProvides the system library operation `park_timeout_ms`.
@detailsExecutes the `park_timeout_ms` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- timeout_msTimeout in milliseconds; negative values usually select blocking or default timeout behavior.
@returnReturns `Bool, ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
functionthread::unpark
Signature
func unpark(thread_id: Int) -> ErrCodefunc unpark(thread_id: Int) -> ErrCode {
return err_from_rc(__thread_unpark(thread_id));
}@briefProvides the system library operation `unpark`.
@detailsExecutes the `unpark` system-library API. The documented parameters define the accepted inputs, ownership requirements, range limits, and timeout behavior for this call. Callers must check returned `ErrCode` values or boolean status values before using the result.
@param
- thread_idNative thread identifier targeted or returned by the operation.
@returnReturns `ErrCode`; on success the error code is `std.OK` or `OK`, and on failure the error code describes the failure while any returned value contains the usable partial result when available.
Variables
Class fields (var).
varthread::JoinHandle.h
Type
Int@brief`h` field.
@detailsStores the underlying runtime handle. The field type is `Int`, and it is maintained by the constructors and methods of `JoinHandle`.
var h: Int;
/*
@brief `active` field.varthread::JoinHandle.active
Type
Bool@brief`active` field.
@detailsHolds the `active` value for each `JoinHandle` instance. The field type is `Bool`, and constructors and methods keep it synchronized with the object's runtime state.
var active: Bool;
/*varthread::Builder.name
Type
String@brief`name` field.
@detailsHolds the `name` value for each `Builder` instance. The field type is `String`, and constructors and methods keep it synchronized with the object's runtime state.
var name: String;
/*
@brief `stack_size_kb` field.varthread::Builder.stack_size_kb
Type
Int@brief`stack_size_kb` field.
@detailsHolds the `stack_size_kb` value for each `Builder` instance. The field type is `Int`, and constructors and methods keep it synchronized with the object's runtime state.
var stack_size_kb: Int;
/*
@brief `detached` field.varthread::Builder.detached
Type
Bool@brief`detached` field.
@detailsHolds the `detached` value for each `Builder` instance. The field type is `Bool`, and constructors and methods keep it synchronized with the object's runtime state.
var detached: Bool;
/*varthread::CancelToken.flag
Type
sync.Int64@brief`flag` field.
@detailsHolds the `flag` value for each `CancelToken` instance. The field type is `sync.Int64`, and constructors and methods keep it synchronized with the object's runtime state.
var flag: sync.Int64;
/*
@brief `released` field.varthread::CancelToken.released
Type
Bool@brief`released` field.
@detailsHolds the `released` value for each `CancelToken` instance. The field type is `Bool`, and constructors and methods keep it synchronized with the object's runtime state.
var released: Bool;
/*varthread::ThreadLocal<T>.h
Type
Int@brief`h` field.
@detailsStores the underlying runtime handle. The field type is `Int`, and it is maintained by the constructors and methods of `ThreadLocal`.
var h: Int;
/*
@brief `active` field.varthread::ThreadLocal<T>.default_value
Type
T@brief`default_value` field.
@detailsHolds the `default_value` value for each `ThreadLocal` instance. The field type is `T`, and constructors and methods keep it synchronized with the object's runtime state.
var default_value: T;
/*