|
Maestro 0.1.0
Unified interface for quantum circuit simulation
|
ThreadsPool class for holding and controlling a pool of threads. More...
#include <ThreadsPool.h>
Public Member Functions | |
| ThreadsPool (int nrThreads=0) | |
| Construct a new Thread pool object. | |
| ~ThreadsPool () | |
| Destructor. | |
| void | Stop () |
| Stop all the threads in the threads pool. | |
| void | Start () |
| Start all the threads in the threads pool. | |
| void | AddRunJob (const std::shared_ptr< Job > &job) |
| Add a job to be executed by the threads pool. | |
| void | AddRunJob (std::shared_ptr< Job > &&job) |
| Add a job to be executed by the threads pool. | |
| void | WaitForFinish () |
| Wait for all jobs to finish. | |
| void | Resize (size_t nrThreads) |
| Resize the threads pool. | |
| void | SetFinishLimit (size_t limit) |
| Set the finish limit. | |
Friends | |
| class | WorkerThread< ThreadsPool< Job >, Job > |
ThreadsPool class for holding and controlling a pool of threads.
Contains a bunch of threads that can execute jobs, supplying functions to add jobs, wait for their completion, start and stop the threads. Allows adding operations and converting them to prepare the circuit for distributed computing.
| Job | The job class/type. |
Definition at line 38 of file ThreadsPool.h.
|
inlineexplicit |
Construct a new Thread pool object.
Constructs a new Thread pool object with the given number of threads.
| nrThreads | The number of threads to create in the pool. If less than or equal to zero, one thread will be created. Can be resized later. |
Definition at line 50 of file ThreadsPool.h.
|
inline |
Destructor.
Destroy the threads pool object. Before destroying, stops all threads and waits for their completion.
Definition at line 64 of file ThreadsPool.h.
|
inline |
Add a job to be executed by the threads pool.
Adds a job to the queue of jobs to be executed by the threads pool. Notifies one thread that there is a new job to execute.
| job | The job to be executed. |
Definition at line 105 of file ThreadsPool.h.
|
inline |
Add a job to be executed by the threads pool.
Adds a job to the queue of jobs to be executed by the threads pool. Notifies one thread that there is a new job to execute.
| job | The job to be executed. |
Definition at line 121 of file ThreadsPool.h.
|
inline |
Resize the threads pool.
Resizes the threads pool to the given number of threads. If the new size is greater than the current size, new threads will be created and started. If the new size is less than the current size, excess threads will be stopped.
| nrThreads | The new number of threads in the pool. If less than or equal to zero, one thread will be created or remain. |
Definition at line 162 of file ThreadsPool.h.
|
inline |
Set the finish limit.
Sets the finish limit for the threads pool. The finish limit is the number of jobs that need to be finished before WaitForFinish() returns. If no finish limit is set, WaitForFinish() will wait indefinitely.
| limit | The finish limit. Default is std::numeric_limits<size_t>::max(). |
Definition at line 201 of file ThreadsPool.h.
|
inline |
Start all the threads in the threads pool.
Starts all the threads in the threads pool.
Definition at line 93 of file ThreadsPool.h.
|
inline |
Stop all the threads in the threads pool.
Stops all the threads and clears the threads pool. Waits for all threads to complete before returning.
Definition at line 72 of file ThreadsPool.h.
|
inline |
Wait for all jobs to finish.
Waits for all jobs to finish executing. This function will block until the number of finished jobs reaches the finish limit set by SetFinishLimit(). If no finish limit is set, it will wait indefinitely.
Definition at line 138 of file ThreadsPool.h.
|
friend |
Definition at line 1 of file ThreadsPool.h.