iLab Neuromorphic Robotics Toolkit
0.1
|
#include <nrt/Core/Design/ThreadPool.H>
The ThreadPool class is used to run a potentially large set of jobs on a fixed number of threads.
Definition at line 48 of file ThreadPool.H.
Public Member Functions | |
ThreadPool (size_t const numThreads=4) | |
Start a threadpool with the given number of threads. | |
~ThreadPool () | |
Detach() all running threads. | |
template<class RETURN_TYPE > | |
std::future< RETURN_TYPE > | pushJob (std::function< RETURN_TYPE()> job) |
Put a new job onto the work queue and get a future for its completion. More... | |
std::future< void > | pushJobs (std::vector< std::function< void()> > jobs) |
Put a set of jobs onto the work queue and get a future for their completion. More... | |
void | joinAll () |
Wait for all jobs to finish and resize the thread pool to zero. More... | |
void | resize (size_t const numThreads) |
Resize the number of available workers. | |
size_t | numWorkers () |
Get the number of threads in the pool. | |
size_t | numJobs () |
Get the number of jobs left in the queue. | |
bool | busy () |
Returns true if all workers in the pool are currently in use. | |
template<> | |
std::future< void > | pushJob (std::function< void()> job) |
|
inline |
Put a new job onto the work queue and get a future for its completion.
Use this method to push a single job onto the work queue. The returned future will be linked to the return value of the function that you push, such that a call to the returned future's get() method will block until your function has finished executing. The future's get() method will then return whatever value your method returned.
job | The function to be pushed onto the work queue |
RETURN_TYPE | The return type of the function being pushed onto the work queue. |
Definition at line 100 of file ThreadPoolImpl.H.
|
inline |
Put a set of jobs onto the work queue and get a future for their completion.
Use this method to push a set of jobs onto the queue simultaneously. The return future will block on a call to wait() until all of the functions in the vector have completed. If you need to actually get the return values of the functions you're pushing, then you must use the singular pushJob() method instead.
jobs | A set of jobs to be executed by the thread pool. |
Definition at line 119 of file ThreadPoolImpl.H.
|
inline |
Wait for all jobs to finish and resize the thread pool to zero.
Must call resize() to reset the thread pool if doing a restart
Definition at line 133 of file ThreadPoolImpl.H.