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 4
State of the thread pool.
Result of attempting to submit a task to the pool.
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();Thread[] workersTask[] taskQueuesize_t queueHeadsize_t queueTailsize_t queueCountsize_t queueCapacityMutex mutexCondition workAvailableCondition queueNotFullPoolState state_size_t activeWorkers_ulong tasksCompleted_ulong tasksSubmitted_size_t numWorkers_bool waitForTasks_ThreadPool create(size_t numWorkers = 0, size_t queueCapacity = 1024) @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.void workerLoop() @trusted