Thread Pool¶
| Spice | |
|---|---|
ThreadPool struct¶
A thread pool that can be used to run multiple jobs in parallel. Thread pools in Spice work with a fixed number of worker threads, that are created when the pool is started. After that, an arbitrary number of jobs can be queued to be run by the pool. The pool will then run as many jobs as possible in parallel.
Constructors¶
ctor¶
| Spice | |
|---|---|
Create a new thread pool.
Parameters
| Name | Type | Description |
|---|---|---|
workerThreadCount |
unsigned short |
(default: 0s) |
Methods¶
start¶
| Spice | |
|---|---|
Start the thread pool.
stop¶
| Spice | |
|---|---|
Finish the running jobs and stop the thread pool.
join¶
| Spice | |
|---|---|
Wait for all queued jobs to finish and stop the thread pool.
enqueue¶
| Spice | |
|---|---|
Enqueue a job to be run by the thread pool.
Parameters
| Name | Type | Description |
|---|---|---|
job |
const p()& |
The job routine to enqueue. |
pause¶
| Spice | |
|---|---|
Pause the thread pool. The worker threads will finish their current job and then wait for the pool to be resumed.
resume¶
| Spice | |
|---|---|
Resume the thread pool.
isPaused¶
| Spice | |
|---|---|
Check if the thread pool is paused.
Returns: bool
getRunningJobCount¶
| Spice | |
|---|---|
Retrieve the number of jobs that are currently running.
Returns: unsigned short
getQueuedJobCount¶
| Spice | |
|---|---|
Retrieve the number of jobs that are currently queued.
Returns: unsigned short
getWorkerThreadCount¶
| Spice | |
|---|---|
Retrieve the number of worker threads.
Returns: unsigned short