Thread pool maintainer.
More...
#include <base/concurrency/ThreadPool.h>
Thread pool maintainer.
Pool of threads used to run 'm' jobs using 'n' threads. The implementation is MT-safe.
- Version
- 1.0
◆ ThreadPool() [1/2]
Initializes thread pool with no threads.
- Parameters
-
provider | The job provider. |
◆ ThreadPool() [2/2]
ThreadPool::ThreadPool |
( |
JobProvider * |
provider, |
|
|
unsigned int |
threads |
|
) |
| |
|
noexcept |
Initializes thread pool with specified number of threads.
- Parameters
-
provider | The job provider. |
threads | The initial number of threads in the pool. |
◆ ~ThreadPool()
ThreadPool::~ThreadPool |
( |
| ) |
|
|
noexcept |
Destroys the thread pool.
◆ getThreads()
unsigned int ThreadPool::getThreads |
( |
| ) |
const |
|
noexcept |
Returns the desired number of threads of the pool.
◆ join()
void ThreadPool::join |
( |
| ) |
|
|
noexcept |
Waits for all the threads to terminate. All waiting jobs of the pool are executed first unless the pool has been explicitly terminated.
◆ post()
void ThreadPool::post |
( |
| ) |
|
|
noexcept |
The job provider is required to invoke this function when a job becomes available.
◆ setThreads()
void ThreadPool::setThreads |
( |
unsigned int |
value | ) |
|
Sets the desired number of threads of the pool. Blocks until accomplished. Raises ThreadPoolException is the pool has been terminated.
◆ terminate()
void ThreadPool::terminate |
( |
| ) |
|
|
noexcept |
Asks all the threads to terminate. Jobs that have not been started are not executed.