library of assembled shared sources

http://lass.cocamware.com

lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy > Class Template Reference

#include <thread_pool.h>

Collaboration diagram for lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >:

Collaboration graph
[legend]

Data Structures

class  ConsumerThread

Public Types

enum  { autoNumberOfThreads = 0, unlimitedNumberOfTasks = 0 }
typedef TaskType TTask
typedef ConsumerType TConsumer
typedef IdlePolicy TIdlePolicy
typedef ParticipationPolicy
< TaskType, ConsumerType,
IdlePolicy > 
TParticipationPolicy
typedef ThreadPool< TaskType,
ConsumerType, IdlePolicy,
ParticipationPolicy > 
TSelf

Public Member Functions

 ThreadPool (size_t numberOfThreads=autoNumberOfThreads, size_t maximumNumberOfTasksInQueue=unlimitedNumberOfTasks, const TConsumer &consumerPrototype=TConsumer(), const char *name=0)
 ~ThreadPool ()
void addTask (typename util::CallTraits< TTask >::TParam task)
 submit a task to the pool, and block if queue is full.
void completeAllTasks ()
 blocks until all tasks in the queue are completed control thread participates as consumer if policy allows for it.
void clearQueue ()
 clear queue without completing tasks.
const size_t numberOfThreads () const

Private Types

typedef stde::lock_free_queue
< TTask
TTaskQueue

Private Member Functions

void startThreads (const TConsumer &consumerPrototype, const char *name)
 Allocate a bunch of threads and run them.
void stopThreads (size_t numAllocatedThreads)
 Deallocate the threads and free memory.

Private Attributes

TTaskQueue waitingTasks_
std::auto_ptr
< experimental::RemoteExceptionBase
error_
ConsumerThreadthreads_
unsigned long mSecsToSleep_
size_t numThreads_
size_t maxWaitingTasks_
volatile size_t numWaitingTasks_
volatile size_t numRunningTasks_
volatile bool shutDown_
volatile bool abort_

Friends

class ConsumerThread

Detailed Description

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
class lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >

Definition at line 251 of file thread_pool.h.


Member Typedef Documentation

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
typedef TaskType lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::TTask

Definition at line 255 of file thread_pool.h.

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
typedef ConsumerType lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::TConsumer

Definition at line 256 of file thread_pool.h.

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
typedef IdlePolicy lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::TIdlePolicy

Definition at line 257 of file thread_pool.h.

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
typedef ParticipationPolicy<TaskType, ConsumerType, IdlePolicy> lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::TParticipationPolicy

Definition at line 258 of file thread_pool.h.

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
typedef ThreadPool<TaskType, ConsumerType, IdlePolicy, ParticipationPolicy> lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::TSelf

Definition at line 259 of file thread_pool.h.

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
typedef stde::lock_free_queue<TTask> lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::TTaskQueue [private]

Definition at line 280 of file thread_pool.h.


Member Enumeration Documentation

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
anonymous enum

Enumerator:
autoNumberOfThreads 
unlimitedNumberOfTasks 

Definition at line 261 of file thread_pool.h.


Constructor & Destructor Documentation

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
ThreadPool::ThreadPool ( size_t  numberOfThreads = autoNumberOfThreads,
size_t  maximumNumberOfTasksInQueue = unlimitedNumberOfTasks,
const TConsumer consumerPrototype = TConsumer(),
const char *  name = 0 
) [inline]

Parameters:
iNumberOfThreads specify number of producer threads. Specify autoNumberOfThreads to automatically use as many threads as processors.
mNumberOfTasksInQueue specifiy the maximum number of tasks that may be waiting in the queue. Specify unlimitedNumberOfTasks to have an unlimited queue.

Definition at line 62 of file thread_pool.inl.

References LASS_ENFORCE, lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::numThreads_, and lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::startThreads().

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
ThreadPool::~ThreadPool (  )  [inline]


Member Function Documentation

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
void ThreadPool::addTask ( typename util::CallTraits< TTask >::TParam  task  )  [inline]

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
void ThreadPool::completeAllTasks (  )  [inline]

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
void ThreadPool::clearQueue (  )  [inline]

clear queue without completing tasks.

All waiting tasks in the queue are simply thrown away without ever being completed.

Definition at line 153 of file thread_pool.inl.

References lass::stde::lock_free_queue< T, FixedAllocator >::pop(), and lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::waitingTasks_.

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
const size_t ThreadPool::numberOfThreads (  )  const [inline]

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
void ThreadPool::startThreads ( const TConsumer consumerPrototype,
const char *  name 
) [inline, private]

template<typename T , typename C , typename IP , template< typename, typename, typename > class PP>
void ThreadPool::stopThreads ( size_t  numAllocatedThreads  )  [inline, private]


Friends And Related Function Documentation

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
friend class ConsumerThread [friend]


Field Documentation

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
TTaskQueue lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::waitingTasks_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
std::auto_ptr<experimental::RemoteExceptionBase> lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::error_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
ConsumerThread* lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::threads_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
unsigned long lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::mSecsToSleep_ [private]

Definition at line 300 of file thread_pool.h.

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
size_t lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::numThreads_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
size_t lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::maxWaitingTasks_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
volatile size_t lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::numWaitingTasks_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
volatile size_t lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::numRunningTasks_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
volatile bool lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::shutDown_ [private]

template<typename TaskType = Callback0, typename ConsumerType = DefaultConsumer<TaskType>, typename IdlePolicy = Signaled, template< typename, typename, typename > class ParticipationPolicy = NotParticipating>
volatile bool lass::util::ThreadPool< TaskType, ConsumerType, IdlePolicy, ParticipationPolicy >::abort_ [private]


The documentation for this class was generated from the following files:

Generated on Mon Nov 10 14:22:17 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo