Template providing a thread pool for asynchronous tasks.
More...
#include "thread_pool.h"
|
| void | async (Task *const task) |
| | Run a task asynchrounously. More...
|
| |
| bool | isRunning () const |
| | Checks if the thread pool is currently running. More...
|
| |
| void | run (Task *const task) |
| | Queue and run a task. More...
|
| |
| size_t | start (long num=2L) |
| | Starts the thread pool. More...
|
| |
| void | stop () |
| | Stops the thread pool. More...
|
| |
| void | wait () |
| | Waits for all tasks to get finished. More...
|
| |
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.nosp@m.@hgl.nosp@m..rang.nosp@m.un.d.nosp@m.e
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