EgretDoc
Back to Home
Location:system/concurrent.thread_pool

Module

Module documentation.

moduleconcurrent.thread_pool

Classes

Classes and inheritance.

classconcurrent.thread_pool::ParallelForContext
@brief`ParallelForContext` type.
@details`ParallelForContext` 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 ParallelForContext {
    /*
    @brief `fn` field.
classconcurrent.thread_pool::ThreadPool
@brief`ThreadPool` type.
@details`ThreadPool` 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 ThreadPool {
    /*
    @brief `workers` field.

Functions

Free functions and class methods.

functionconcurrent.thread_pool::noop_pool_job
Signaturefunc noop_pool_job(arg: Any) -> Int
func noop_pool_job(arg: Any) -> Int {
    return 0;
}
@briefProvides the system library operation `noop_pool_job`.
@detailsExecutes the `noop_pool_job` 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
  • argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
@returnReturns the operation result as `Int`.
functionconcurrent.thread_pool::ParallelForContext.init
Signaturefunc init(self: concurrent.thread_pool.ParallelForContext, fn: (Any, Int, Int) -> Int, ctx: Any, start: Int, end: Int, wg: sync.WaitGroup, rc: sync.Int64) -> Void
    func init(self: concurrent.thread_pool.ParallelForContext, fn: (Any, Int, Int) -> Int, ctx: Any, start: Int, end: Int, wg: sync.WaitGroup, rc: sync.Int64) -> Void {
        self.fn = fn;
        self.ctx = ctx;
@briefInitializes a `ParallelForContext` instance.
@detailsEstablishes the initial field state for `ParallelForContext` 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.
  • fnFunction or callback invoked by the operation.
  • ctxNative context pointer or runtime context object used by the operation.
  • startZero-based starting index, byte offset, or range boundary for the operation.
  • endEnd index, byte offset, or range boundary for the operation.
  • wgWait-group object used to synchronize concurrent work.
  • rcReturn code or runtime status code produced by a native call.
@returnVoid
functionconcurrent.thread_pool::ParallelForContext.deinit
Signaturefunc deinit(self: concurrent.thread_pool.ParallelForContext) -> Void
    func deinit(self: concurrent.thread_pool.ParallelForContext) -> Void {
    }
@briefReleases fallback resources at the end of the `ParallelForContext` 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
functionconcurrent.thread_pool::ParallelForContext.wg_ref
Signaturefunc wg_ref(self: concurrent.thread_pool.ParallelForContext) -> sync.WaitGroup
    func wg_ref(self: concurrent.thread_pool.ParallelForContext) -> sync.WaitGroup {
        return self.wg => sync.WaitGroup;
    }
@briefProvides the system library operation `ParallelForContext.wg_ref`.
@detailsExecutes the `wg_ref` 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 `sync.WaitGroup`.
functionconcurrent.thread_pool::ParallelForContext.rc_ref
Signaturefunc rc_ref(self: concurrent.thread_pool.ParallelForContext) -> sync.Int64
    func rc_ref(self: concurrent.thread_pool.ParallelForContext) -> sync.Int64 {
        return self.rc => sync.Int64;
    }
@briefProvides the system library operation `ParallelForContext.rc_ref`.
@detailsExecutes the `rc_ref` 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 `sync.Int64`.
functionconcurrent.thread_pool::parallel_for_worker
Signaturefunc parallel_for_worker(arg: Any) -> Int
func parallel_for_worker(arg: Any) -> Int {
    let p: concurrent.thread_pool.ParallelForContext = arg => concurrent.thread_pool.ParallelForContext;
    let r: Int = p.fn(p.ctx, p.start, p.end);
@briefProvides the system library operation `parallel_for_worker`.
@detailsExecutes the `parallel_for_worker` 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
  • argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
@returnReturns the operation result as `Int`.
functionconcurrent.thread_pool::ThreadPool.init
Signaturefunc init(self: concurrent.thread_pool.ThreadPool, thread_count: Int, queue_capacity: Int) -> Void
    func init(self: concurrent.thread_pool.ThreadPool, thread_count: Int, queue_capacity: Int) -> Void {
        self.workers = new collections.Vector<thread.JoinHandle>();
        self.queue = new concurrent.job_queue.JobQueue(queue_capacity);
@briefInitializes a `ThreadPool` instance.
@detailsEstablishes the initial field state for `ThreadPool` 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.
  • thread_countNumber of worker threads requested for concurrent execution.
  • queue_capacityMaximum number of queued jobs or tasks retained by the queue.
@returnVoid
functionconcurrent.thread_pool::ThreadPool.submit
Signaturefunc submit(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any) -> concurrent.job_queue.Job?
    func submit(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any) -> concurrent.job_queue.Job? {
        if self.shutting_down {
            return nil;
@briefProvides the system library operation `ThreadPool.submit`.
@detailsExecutes the `submit` 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 the operation result as `concurrent.job_queue.Job?`.
functionconcurrent.thread_pool::ThreadPool.submit_or
Signaturefunc submit_or(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any, def: concurrent.job_queue.Job) -> concurrent.job_queue.Job
    func submit_or(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any, def: concurrent.job_queue.Job) -> concurrent.job_queue.Job {
        if self.shutting_down {
            return def;
@briefProvides the system library operation `ThreadPool.submit_or`.
@detailsExecutes the `submit_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.
  • 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.
  • defDefault value returned or used when the requested value is absent, invalid, or cannot be decoded.
@returnReturns the operation result as `concurrent.job_queue.Job`.
functionconcurrent.thread_pool::ThreadPool.submit_detached
Signaturefunc submit_detached(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any) -> Bool
    func submit_detached(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any) -> Bool {
        if self.shutting_down {
            return false;
@briefProvides the system library operation `ThreadPool.submit_detached`.
@detailsExecutes the `submit_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 a boolean result; true means the condition holds or the operation succeeded.
functionconcurrent.thread_pool::ThreadPool.submit_detached_wg
Signaturefunc submit_detached_wg(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any, wg: sync.WaitGroup) -> Bool
    func submit_detached_wg(self: concurrent.thread_pool.ThreadPool, f: (Any) -> Int, arg: Any, wg: sync.WaitGroup) -> Bool {
        if self.shutting_down {
            return false;
@briefProvides the system library operation `ThreadPool.submit_detached_wg`.
@detailsExecutes the `submit_detached_wg` 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.
  • wgWait-group object used to synchronize concurrent work.
@returnReturns a boolean result; true means the condition holds or the operation succeeded.
functionconcurrent.thread_pool::ThreadPool.parallel_for
Signaturefunc parallel_for(self: concurrent.thread_pool.ThreadPool, total: Int, min_grain: Int, ctx: Any, fn: (Any, Int, Int) -> Int) -> Int
    func parallel_for(self: concurrent.thread_pool.ThreadPool, total: Int, min_grain: Int, ctx: Any, fn: (Any, Int, Int) -> Int) -> Int {
        if total <= 0 {
            return 0;
@briefProvides the system library operation `ThreadPool.parallel_for`.
@detailsExecutes the `parallel_for` 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.
  • totalTotal number of bytes, elements, rows, or operations accumulated by the caller.
  • min_grainMinimum work-grain size used when splitting parallel work.
  • ctxNative context pointer or runtime context object used by the operation.
  • fnFunction or callback invoked by the operation.
@returnReturns the operation result as `Int`.
functionconcurrent.thread_pool::ThreadPool.shutdown
Signaturefunc shutdown(self: concurrent.thread_pool.ThreadPool) -> Void
    func shutdown(self: concurrent.thread_pool.ThreadPool) -> Void {
        if self.shutting_down {
            return;
@briefProvides the system library operation `ThreadPool.shutdown`.
@detailsExecutes the `shutdown` 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
functionconcurrent.thread_pool::ThreadPool.wait
Signaturefunc wait(self: concurrent.thread_pool.ThreadPool) -> Void
    func wait(self: concurrent.thread_pool.ThreadPool) -> Void {
        _ = self.shutdown();
        loop (let worker_index: Int = 0; worker_index < self.workers.len(); worker_index += 1) {
@briefProvides the system library operation `ThreadPool.wait`.
@detailsExecutes the `wait` 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
functionconcurrent.thread_pool::ThreadPool.release_resources
Signaturefunc release_resources(self: concurrent.thread_pool.ThreadPool) -> Void
    func release_resources(self: concurrent.thread_pool.ThreadPool) -> Void {
        if !self.queue_released {
            dispose self.queue;
@briefProvides the system library operation `ThreadPool.release_resources`.
@detailsExecutes the `release_resources` 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
functionconcurrent.thread_pool::ThreadPool.dispose
Signaturefunc dispose(self: concurrent.thread_pool.ThreadPool) -> Void
    func dispose(self: concurrent.thread_pool.ThreadPool) -> Void {
        _ = self.wait();
    }
@briefExplicitly releases resources owned by `ThreadPool`.
@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
functionconcurrent.thread_pool::ThreadPool.deinit
Signaturefunc deinit(self: concurrent.thread_pool.ThreadPool) -> Void
    func deinit(self: concurrent.thread_pool.ThreadPool) -> Void {
        if self.workers_released {
            return;
@briefReleases fallback resources at the end of the `ThreadPool` 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
functionconcurrent.thread_pool::ThreadPool.worker_count
Signaturefunc worker_count(self: concurrent.thread_pool.ThreadPool) -> Int
    func worker_count(self: concurrent.thread_pool.ThreadPool) -> Int {
        return self.workers.len();
    }
@briefProvides the system library operation `ThreadPool.worker_count`.
@detailsExecutes the `worker_count` 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 `Int`.
functionconcurrent.thread_pool::thread_pool_worker
Signaturefunc thread_pool_worker(arg: Any) -> Int
func thread_pool_worker(arg: Any) -> Int {
    let pool: concurrent.thread_pool.ThreadPool = arg => concurrent.thread_pool.ThreadPool;
    let stop: concurrent.job_queue.Job = new concurrent.job_queue.Job(noop_pool_job, 0);
@briefProvides the system library operation `thread_pool_worker`.
@detailsExecutes the `thread_pool_worker` 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
  • argOpaque argument value passed through to a callback, thread entry point, or runtime helper.
@returnReturns the operation result as `Int`.

Variables

Class fields (var).

varconcurrent.thread_pool::ParallelForContext.fn
Type(Any, Int, Int) -> Int
@brief`fn` field.
@detailsHolds the `fn` value for each `ParallelForContext` instance. The field type is `(Any, Int, Int) -> Int`, and constructors and methods keep it synchronized with the object's runtime state.
    var fn: (Any, Int, Int) -> Int;
    /*
    @brief `ctx` field.
varconcurrent.thread_pool::ParallelForContext.ctx
TypeAny
@brief`ctx` field.
@detailsHolds the `ctx` value for each `ParallelForContext` instance. The field type is `Any`, and constructors and methods keep it synchronized with the object's runtime state.
    var ctx: Any;
    /*
    @brief `start` field.
varconcurrent.thread_pool::ParallelForContext.start
TypeInt
@brief`start` field.
@detailsHolds the `start` value for each `ParallelForContext` instance. The field type is `Int`, and constructors and methods keep it synchronized with the object's runtime state.
    var start: Int;
    /*
    @brief `end` field.
varconcurrent.thread_pool::ParallelForContext.end
TypeInt
@brief`end` field.
@detailsHolds the `end` value for each `ParallelForContext` instance. The field type is `Int`, and constructors and methods keep it synchronized with the object's runtime state.
    var end: Int;
    /*
    @brief `wg` field.
varconcurrent.thread_pool::ParallelForContext.wg
TypeAny
@brief`wg` field.
@detailsHolds the `wg` value for each `ParallelForContext` instance. The field type is `Any`, and constructors and methods keep it synchronized with the object's runtime state.
    var wg: Any;
    /*
    @brief `rc` field.
varconcurrent.thread_pool::ParallelForContext.rc
TypeAny
@brief`rc` field.
@detailsHolds the `rc` value for each `ParallelForContext` instance. The field type is `Any`, and constructors and methods keep it synchronized with the object's runtime state.
    var rc: Any;

    /*
varconcurrent.thread_pool::ThreadPool.workers
Typecollections.Vector<thread.JoinHandle>
@brief`workers` field.
@detailsHolds the `workers` value for each `ThreadPool` instance. The field type is `collections.Vector<thread.JoinHandle>`, and constructors and methods keep it synchronized with the object's runtime state.
    var workers: collections.Vector<thread.JoinHandle>;
    /*
    @brief `queue` field.
varconcurrent.thread_pool::ThreadPool.queue
Typeconcurrent.job_queue.JobQueue
@brief`queue` field.
@detailsHolds the `queue` value for each `ThreadPool` instance. The field type is `concurrent.job_queue.JobQueue`, and constructors and methods keep it synchronized with the object's runtime state.
    var queue: concurrent.job_queue.JobQueue;
    /*
    @brief `shutting_down` field.
varconcurrent.thread_pool::ThreadPool.shutting_down
TypeBool
@brief`shutting_down` field.
@detailsHolds the `shutting_down` value for each `ThreadPool` instance. The field type is `Bool`, and constructors and methods keep it synchronized with the object's runtime state.
    var shutting_down: Bool;
    /*
    @brief `queue_released` field.
varconcurrent.thread_pool::ThreadPool.queue_released
TypeBool
@brief`queue_released` field.
@detailsHolds the `queue_released` value for each `ThreadPool` instance. The field type is `Bool`, and constructors and methods keep it synchronized with the object's runtime state.
    var queue_released: Bool;
    /*
    @brief `workers_released` field.
varconcurrent.thread_pool::ThreadPool.workers_released
TypeBool
@brief`workers_released` field.
@detailsHolds the `workers_released` value for each `ThreadPool` instance. The field type is `Bool`, and constructors and methods keep it synchronized with the object's runtime state.
    var workers_released: Bool;
    /*
    @brief `thread_count` field.
varconcurrent.thread_pool::ThreadPool.thread_count
TypeInt
@brief`thread_count` field.
@detailsHolds the `thread_count` value for each `ThreadPool` instance. The field type is `Int`, and constructors and methods keep it synchronized with the object's runtime state.
    var thread_count: Int;

    /*