SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
A basic thread pool that executes functors in separate threads. More...
#include <ThreadPool.h>
Public Member Functions | |
ThreadPool (unsigned int maxThreads=0) | |
Initialize thread pool with maxThreads threads spawned to execute tasks. | |
template<typename Function , typename... Types> | |
std::future< ReturnType > | operator() (Function &&function, Types &&... args) |
Add a task to be performed by the thread queue. More... | |
Protected Member Functions | |
void | initialize () |
std::future< ReturnType > | appendToQueue (std::function< ReturnType()> &&task) |
Append a functor with no inputs to the task queue. More... | |
void | execute () |
Run by a worker thread: poll the task queue for tasks to perform. More... | |
virtual void | exec () |
A basic thread pool that executes functors in separate threads.
It accepts the number of threads to build at construction, and waits for all tasks to complete before being destroyed. The ReturnType is a default-constructible type that tasks return via std::future.
|
protected |
Append a functor with no inputs to the task queue.
This is used in tandem with std::bind to construct the class's call method.
|
inlineprotected |
Run by a worker thread: poll the task queue for tasks to perform.
NOTE: the single layer of misdirection ensures that we launch a thread using the correct method address.
|
inline |
Add a task to be performed by the thread queue.
Once a thread becomes available, it will pop the task from the queue and execute it. The return value can be accessed from the returned future.