Clarisse 4.0 SP5b SDK  4.0.0.0.5.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Friends | List of all members
SysThreadPool Class Reference

A thread pool that dispatches tasks added in the queue to a number of worker threads. More...

Inheritance diagram for SysThreadPool:
CoreBaseObject CoreBaseType

Public Member Functions

 SysThreadPool (const unsigned int &max_thread_count)
 
void add (SysThreadPoolTask &item, const bool &auto_delete=true, const bool &blocking=true)
 Add a new task to the pool and starts it if worker threads are are available.
 
bool wait_until_completed ()
 Wait until all tasks have been dispatched and completed by workers.
 
void shutdown ()
 Purge all unprocessed tasks and kill all threads.
 
const unsigned int & get_max_thread_count () const
 return the number of worker thread allocated for the pool
 
const bool & is_running () const
 return if the pool is currently running. A running pool has necessarely tasks beeing processed by workers. Typically after a shutdown(), is_running() returns false
 
- Public Member Functions inherited from CoreBaseObject
bool is_kindof (const CoreBaseObject &object) const
 
virtual size_t get_memory_size () const
 
CoreString get_class_info_name () const
 
CoreString get_class_interface () const
 
const unsigned long & get_class_info_id () const
 
bool is_kindof (const CoreClassInfo &cinfo) const
 
virtual const CoreClassInfoget_class_info () const
 
bool operator== (const CoreBaseObject &obj) const
 
template<class T >
T * cast ()
 
template<class T >
const T * cast () const
 
- Public Member Functions inherited from CoreBaseType
bool is_kindof (const CoreClassInfo &cinfo) const
 
bool operator== (const CoreBaseType &obj) const
 

Friends

class SysThreadPoolWorker
 

Additional Inherited Members

- Static Public Member Functions inherited from CoreBaseObject
static const CoreClassInfoclass_info ()
 
static bool ___class_destructor__ (void *instance, const bool &is_array)
 
template<class T >
static T * cast (CoreBaseObject *object)
 
template<class T >
static const T * cast (const CoreBaseObject *object)
 

Detailed Description

A thread pool that dispatches tasks added in the queue to a number of worker threads.

Within a thread pool, there are many more pending tasks that the number of worker threads. As soon a worker completes its tasks, it requests the next available task from the task queue if any available. If there are no pending tasks the workers simply sleeps and waits for more tasks to be dispatched.

Constructor & Destructor Documentation

SysThreadPool::SysThreadPool ( const unsigned int &  max_thread_count)
explicit
Parameters
max_thread_countspecifies the number of worker threads dedicated to the pool

Member Function Documentation

void SysThreadPool::add ( SysThreadPoolTask item,
const bool &  auto_delete = true,
const bool &  blocking = true 
)

Add a new task to the pool and starts it if worker threads are are available.

Parameters
itemThe task to be executed by an available worker
auto_deleteIf true the worker will automatically delete the task after complition
blockingIf true the pool is blocked until a worker gets available. This is very useful if you support an abort and you want to avoid sending all tasks to the pool
bool SysThreadPool::wait_until_completed ( )

Wait until all tasks have been dispatched and completed by workers.

Returns
always true