JobSystem Class
A fixed-size thread pool for parallel job execution. More...
Declaration
Public Constructors Index
| JobSystem (const std::size_t maxWorkerCount) | |
|
Constructs the job system and spawns worker threads. More... | |
Public Member Functions Index
template <typename Fn> | |
| void | runAndWait (std::size_t jobCount, Fn &&fn) |
|
Enqueues jobCount jobs and blocks until all have finished. More... | |
Private Member Attributes Index
| std::queue< std::function< void()> > | jobQueue_ |
| std::mutex | mutex_ |
| std::condition_variable_any | jobCondition_ |
| std::condition_variable | doneCondition_ |
| std::size_t | maxWorkerCount_ |
|
Maximum number of worker threads. More... | |
| std::size_t | pendingJobCount_ = 0 |
|
Number of jobs in the current batch that have not finished yet. More... | |
| std::vector< std::jthread > | workerThreads_ |
Description
A fixed-size thread pool for parallel job execution.
Maintains a pool of std::jthread workers that pull jobs from a shared queue. runAndWait() enqueues a batch of jobs and blocks until every job in that batch has completed.
Definition at line 38 of file JobSystem.ixx.
Public Constructors
JobSystem()
| inline explicit |
Constructs the job system and spawns worker threads.
- Parameters
-
maxWorkerCount Number of worker threads to create. Typically std::thread::hardware_concurrency().
Definition at line 61 of file JobSystem.ixx.
Reference helios::engine::core::registerComponents.
Public Member Functions
runAndWait()
| inline |
Enqueues jobCount jobs and blocks until all have finished.
Calls fn(i) for each index i in [0, jobCount) on a worker thread. Returns only after every invocation has completed.
- Template Parameters
-
Fn Callable type with signature void(std::size_t).
- Parameters
-
jobCount Number of parallel jobs to dispatch.
fn Job body receiving the job index.
Must not be called concurrently from multiple threads.
Definition at line 103 of file JobSystem.ixx.
Reference helios::engine::core::registerComponents.
Referenced by helios::engine::runtime::world::EntityMutationManager< TEntityManager >::flushParallel.
Private Member Attributes
doneCondition_
|
Definition at line 43 of file JobSystem.ixx.
jobCondition_
|
Definition at line 42 of file JobSystem.ixx.
jobQueue_
|
Definition at line 40 of file JobSystem.ixx.
maxWorkerCount_
|
Maximum number of worker threads.
Definition at line 46 of file JobSystem.ixx.
mutex_
|
Definition at line 41 of file JobSystem.ixx.
pendingJobCount_
|
Number of jobs in the current batch that have not finished yet.
Definition at line 49 of file JobSystem.ixx.
workerThreads_
|
Definition at line 51 of file JobSystem.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.