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>
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>
Run a task asynchrounously.
This method spawns only one thread and behaves basically like calling
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>
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>
Queue and run a task.
- Parameters:
-
| task | the task to queue and run |
template<void(*)(void *) Worker, class Task , long NUM_THREADS>
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>
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>
Waits for all tasks to get finished.
- Precondition:
- a call to stop() is neccessary if not waiting for an async job