CLAM::ThreadPool Class Reference

This is a simple variety of thread pool. More...

#include <ThreadPool.hxx>

List of all members.

Public Member Functions

 ThreadPool (int initialNumberOfThreads=10, bool isRealtime=false)
 The constructor.
 ~ThreadPool ()
PooledThreadGetThreadFromPool ()
 This gets a thread from the pool.
void ReturnThreadToPool (PooledThread *aThread)
void EmptyPool ()

Detailed Description

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.

Author:
Greg Kellum [gkellum@iua.upf.edu] 7/20/2007
Since:
CLAM v1.1.

Definition at line 51 of file ThreadPool.hxx.


Constructor & Destructor Documentation

CLAM::ThreadPool::ThreadPool ( int  initialNumberOfThreads = 10,
bool  isRealtime = false 
)

The constructor.

  • initialNumberOfThreads - self-explanatory
  • isRealtime - if the thread is declared as realtime, it will get the highest level of scheduling priority possible which might cause threads of this pool to run before any other threads. if the thread is declared as not realtime, it will get half the scheduling priority of a realtime thread.

Definition at line 9 of file ThreadPool.cxx.

CLAM::ThreadPool::~ThreadPool (  ) 

Definition at line 17 of file ThreadPool.cxx.

References EmptyPool().


Member Function Documentation

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.


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.3