HGL::Common::ThreadPool< Worker, Task, NUM_THREADS > Class Template Reference
[Utility classes]

Template providing a thread pool for asynchronous tasks. More...

#include <thread_pool.h>

Inheritance diagram for HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

void async (Task *const task)
 Run a task asynchrounously.
bool isRunning () const
 Checks if the thread pool is currently running.
void run (Task *const task)
 Queue and run a task.
size_t start (long num=2L)
 Starts the thread pool.
void stop ()
 Stops the thread pool.
void wait ()
 Waits for all tasks to get finished.

Detailed Description

template<void(*)(void *) Worker, class Task, long NUM_THREADS = 64L>
class HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >

Template providing a thread pool for asynchronous tasks.

Template Parameters:
Worker pointer to a function actually performing the task
Task a class containing the arguments for the Worker to do its job
NUM_THREADS maximum number of threads to create
Author:
Heiko Schäfer <heiko@hgl.rangun.de>

Member Function Documentation

template<void(*)(void *) Worker, class Task , long NUM_THREADS>
void HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >::async ( Task *const   task  ) 

Run a task asynchrounously.

This method spawns only one thread and behaves basically like calling

 start();
 run(task);
 stop();

and stops the thread pool after the task is finished.

Parameters:
task the task to run asynchrounously
Postcondition:
it is safe to let the calling thread wait()
template<void(*)(void *) Worker, class Task , long NUM_THREADS>
bool HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >::isRunning (  )  const

Checks if the thread pool is currently running.

Returns:
true if the thread pool is currently running, false otherwise
template<void(*)(void *) Worker, class Task , long NUM_THREADS>
void HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >::run ( Task *const   task  ) 

Queue and run a task.

Parameters:
task the task to queue and run
template<void(*)(void *) Worker, class Task , long NUM_THREADS>
size_t HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >::start ( long  num = 2L  ) 

Starts the thread pool.

Parameters:
num number of threads to start
Returns:
the number of started threads
template<void(*)(void *) Worker, class Task , long NUM_THREADS>
void HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >::stop (  ) 

Stops the thread pool.

All queued tasks get finished and the thread pool stops

Postcondition:
this call is neccessary to let the calling thread wait()
template<void(*)(void *) Worker, class Task , long NUM_THREADS>
void HGL::Common::ThreadPool< Worker, Task, NUM_THREADS >::wait (  ) 

Waits for all tasks to get finished.

Precondition:
a call to stop() is neccessary if not waiting for an async job

Generated on 9 Apr 2014 for hgl 0.5.26~svn by  doxygen 1.6.1