eve.rt.pool
Thread Pool for Parallel Task Execution
This module provides a thread pool implementation for executing tasks across multiple worker threads. It integrates with the EVE runtime layer to enable efficient parallel and concurrent execution patterns.
The thread pool manages a fixed number of worker threads that pull tasks from a shared work queue. This amortizes thread creation overhead and provides backpressure when the system is overloaded.
Copyright
Types 6
State of the thread pool.
Reason a task submission to the pool failed.
Retryability and fatality:
REJECTED— Fatal: the pool is shutting down or stopped.QUEUE_FULL— Retryable after the queue drains.
Recoverable failure of a task submission.
SubmitErrorReason reasonWhy the submission failed.int errnoReserved; OS errors do not apply to pool submissions.A task to be executed by the thread pool.
Tasks are simple delegates that take no arguments and return nothing. Any results should be communicated through captured variables, futures, or channels.
A pool of worker threads for executing tasks in parallel.
The ThreadPool manages a collection of worker threads that execute submitted tasks. Tasks are queued and executed in approximate FIFO order, though no strict ordering is guaranteed due to concurrent execution.
Example:
auto pool = ThreadPool.create(4); // 4 worker threads
pool.start();
pool.submit(() @safe {
// Task code here
});
pool.shutdown();
pool.awaitTermination();private Thread[] workersprivate Task[] taskQueueprivate size_t queueHeadprivate size_t queueTailprivate size_t queueCountprivate size_t queueCapacityprivate Mutex mutexprivate Condition workAvailableprivate Condition queueNotFullprivate PoolState state_private size_t activeWorkers_private ulong tasksCompleted_private ulong tasksSubmitted_private size_t numWorkers_private bool waitForTasks_ThreadPool create(size_t numWorkers = 0, size_t queueCapacity = 1024) static @trustedCreate a new thread pool with the specified number of workers.size_t numWorkers() @property const pure @safe nothrow @nogcGet the number of worker threads in the pool.size_t activeWorkers() @property const @trusted nothrow @nogcGet the number of currently active (executing) workers.ulong completedTasks() @property const @trusted nothrow @nogcGet the total number of tasks that have been completed.ulong submittedTasks() @property const @trusted nothrow @nogcGet the total number of tasks that have been submitted.