This is a simple variety of thread pool. More...
#include <ThreadPool.hxx>
Public Member Functions | |
ThreadPool (int initialNumberOfThreads=10, bool isRealtime=false) | |
The constructor. | |
~ThreadPool () | |
PooledThread * | GetThreadFromPool () |
This gets a thread from the pool. | |
void | ReturnThreadToPool (PooledThread *aThread) |
void | EmptyPool () |
This is a simple variety of thread pool.
This class maintains a collection of threads. When an additional thread is needed and no threads are available in its idle pool, it first checks the status of the threads it has already given out and returns one of those to the client and the rest to the idle pool. If all the threads it has given out are still busy, it creates a new thread.
This class should only be used if a relatively small number of threads is needed, because as the number of threads grows, the scheduling overhead of switching between threads can become a significant drag on your program's performance. If a relatively large number of tasks need to be run on threads, it would be better to use a work queue which is processed by a fixed number of threads.
Definition at line 51 of file ThreadPool.hxx.
CLAM::ThreadPool::ThreadPool | ( | int | initialNumberOfThreads = 10 , |
|
bool | isRealtime = false | |||
) |
The constructor.
Definition at line 9 of file ThreadPool.cxx.
CLAM::ThreadPool::~ThreadPool | ( | ) |
Definition at line 17 of file ThreadPool.cxx.
References EmptyPool().
void CLAM::ThreadPool::EmptyPool | ( | ) |
Definition at line 22 of file ThreadPool.cxx.
References CLAM::Thread::IsRunning(), NULL, and CLAM::Thread::Stop().
Referenced by ~ThreadPool().
PooledThread * CLAM::ThreadPool::GetThreadFromPool | ( | ) |
This gets a thread from the pool.
When an additional thread is needed and no threads are available in its idle pool, it first checks the status of the threads it has already given out and returns one of those to the client and the rest to the idle pool. If all the threads it has given out are still busy, it creates a new thread.
Definition at line 52 of file ThreadPool.cxx.
References CLAM::Thread::IsRunning().
void CLAM::ThreadPool::ReturnThreadToPool | ( | PooledThread * | aThread | ) |
Definition at line 86 of file ThreadPool.cxx.