SG++-Doxygen-Documentation
|
This implements a thread-pool with a pre-specified number of threads that process a list of tasks. More...
#include <ThreadPool.hpp>
Public Types | |
typedef GeneralFunction< void, ThreadPool & > | IdleCallback |
typedef GeneralFunction1< void > | Task |
Public Member Functions | |
void | addTask (Task const &task) |
Adds a single task to the task list (thread-safe). More... | |
void | addTasks (std::vector< Task > const &newTasks) |
Adds a list of tasks to the task list (thread-safe). More... | |
void | join () |
Waits until all threads are finished. More... | |
void | start () |
Starts the threads. More... | |
ThreadPool (size_t numThreads) | |
Creates a ThreadPool that processes available tasks. More... | |
ThreadPool (size_t numThreads, IdleCallback idleCallback) | |
Creates a ThreadPool that processes available tasks. More... | |
void | triggerTermination () |
Sets a termination flag (thread-safe). More... | |
~ThreadPool () | |
Static Public Member Functions | |
static void | doTerminateWhenIdle (ThreadPool &tp) |
Static Public Attributes | |
static IdleCallback | terminateWhenIdle |
This function can be used as a parameter to the constructor if the threads shall terminate as soon as there are no tasks left. More... | |
This implements a thread-pool with a pre-specified number of threads that process a list of tasks.
typedef GeneralFunction<void, ThreadPool &> sgpp::combigrid::ThreadPool::IdleCallback |
typedef GeneralFunction1<void> sgpp::combigrid::ThreadPool::Task |
|
explicit |
Creates a ThreadPool that processes available tasks.
When no more tasks are available, the threads terminate. Another way to terminate earlier is using triggerTermination(). The ThreadPool starts its computation only when start() is called.
sgpp::combigrid::ThreadPool::ThreadPool | ( | size_t | numThreads, |
IdleCallback | idleCallback | ||
) |
Creates a ThreadPool that processes available tasks.
When no more tasks are available, the callback function idleCallback is called. This callback should either add more tasks or call triggerTermination(), which will cause the threads to terminate. The ThreadPool is passed as a parameter to the callback. The ThreadPool starts its computation only when start() is called.
sgpp::combigrid::ThreadPool::~ThreadPool | ( | ) |
References join(), and triggerTermination().
void sgpp::combigrid::ThreadPool::addTask | ( | Task const & | task | ) |
Adds a single task to the task list (thread-safe).
References CGLOG_SURROUND.
void sgpp::combigrid::ThreadPool::addTasks | ( | std::vector< Task > const & | newTasks | ) |
Adds a list of tasks to the task list (thread-safe).
References CGLOG_SURROUND.
Referenced by sgpp::combigrid::LevelManager::addLevelsAdaptiveParallel().
|
static |
References triggerTermination().
void sgpp::combigrid::ThreadPool::join | ( | ) |
Waits until all threads are finished.
Referenced by ~ThreadPool().
void sgpp::combigrid::ThreadPool::start | ( | ) |
Starts the threads.
References CGLOG, CGLOG_SURROUND, and python.statsfileInfo::i.
void sgpp::combigrid::ThreadPool::triggerTermination | ( | ) |
Sets a termination flag (thread-safe).
When a thread completes a task, it will check the termination flag and terminate.
References CGLOG_SURROUND.
Referenced by sgpp::combigrid::LevelManager::addLevelsAdaptiveParallel(), doTerminateWhenIdle(), and ~ThreadPool().
|
static |
This function can be used as a parameter to the constructor if the threads shall terminate as soon as there are no tasks left.
Referenced by sgpp::combigrid::LevelManager::precomputeLevelsParallel().