SG++-Doxygen-Documentation
sgpp::combigrid::ThreadPool Class Reference

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...
 

Detailed Description

This implements a thread-pool with a pre-specified number of threads that process a list of tasks.

Member Typedef Documentation

Constructor & Destructor Documentation

sgpp::combigrid::ThreadPool::ThreadPool ( size_t  numThreads)
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().

Member Function Documentation

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().

void sgpp::combigrid::ThreadPool::doTerminateWhenIdle ( ThreadPool tp)
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().

Member Data Documentation

ThreadPool::IdleCallback sgpp::combigrid::ThreadPool::terminateWhenIdle
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().


The documentation for this class was generated from the following files: