#include <WorkerPool.hpp>
◆ WorkerPool() [1/3]
| WorkerPool::WorkerPool |
( |
int | numWorkers | ) |
|
|
explicit |
Spin up numWorkers persistent threads.
- Parameters
-
| numWorkers | Worker count. Caller picks; a sane default is std::thread::hardware_concurrency() / 2 so we leave half the cores for the rest of the system (server + bots in our test scenario, OS in prod). |
◆ ~WorkerPool()
| WorkerPool::~WorkerPool |
( |
| ) |
|
◆ WorkerPool() [2/3]
◆ WorkerPool() [3/3]
◆ numWorkers()
| int WorkerPool::numWorkers |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Number of worker threads (excluding the calling thread).
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ parallelFor()
| void WorkerPool::parallelFor |
( |
int | count, |
|
|
const std::function< void(int begin, int end)> & | fn ) |
Run fn in parallel over the index range [0, count).
The range is split into numWorkers + 1 chunks (workers + the calling thread), each worker receives one chunk, and the calling thread runs the last chunk inline before waiting for the others. Blocks until every chunk has returned.
fn(begin, end) is called once per chunk with a half-open range. Different threads may be running fn concurrently — fn must be thread-safe with respect to itself, and must not mutate shared state across chunks without explicit synchronization.
◆ workerLoop()
| void WorkerPool::workerLoop |
( |
int | workerId | ) |
|
|
private |
◆ currentChunkSize_
| int WorkerPool::currentChunkSize_ = 0 |
|
private |
◆ currentFn_
| const std::function<void(int, int)>* WorkerPool::currentFn_ = nullptr |
|
private |
◆ currentGeneration_
| int WorkerPool::currentGeneration_ = 0 |
|
private |
◆ currentTotal_
| int WorkerPool::currentTotal_ = 0 |
|
private |
◆ cvDone_
| std::condition_variable WorkerPool::cvDone_ |
|
private |
◆ cvWork_
| std::condition_variable WorkerPool::cvWork_ |
|
private |
◆ mtx_
| std::mutex WorkerPool::mtx_ |
|
private |
◆ outstanding_
| std::atomic<int> WorkerPool::outstanding_ {0} |
|
private |
◆ stop_
| std::atomic<bool> WorkerPool::stop_ {false} |
|
private |
◆ workers_
| std::vector<std::thread> WorkerPool::workers_ |
|
private |
The documentation for this class was generated from the following files: