R3DThreadGroup Class Reference

#include <R3D/Threads/R3DThreadGroup.h>

List of all members.


Detailed Description

This class helps to manage thread resources by helping to cleanup the threads when they are complete.

The class is based off of the Boost::thread_group class. This class adds a maximum number of threads that can be in use at any one time and is a user settable value and NOT based off of hardware capabilities. Thus a user is capable of starting 100 threads on a single processor machine. You have been warned. You should instantiate this class like normal then use the "createThread" method to create your threads. When the maximum number of threads is reached called createThread will result in a blocking operation until another thread is complete and removed from the group. See the docs for the R3DAbstractThread which is a companion class to this class.

Author:
Michael A. Jackson for BlueQuartz Software
Date:
Apr 6, 2009
Version:
$Revision$


Public Member Functions

int getMaxThreads ()
 Returns the maximum number of threads this group is managing.
void setShouldDeleteThreadsOnDestruction (bool c)
 When this class is destroyed, the pointers to the actual thread objects will be 'delete'ed if this is set to TRUE.
int waitForOpenSlot ()
 Waits for an open slot to start another thread.
template<typename T>
boost::thread * startThread (T t)
 Creates a new thread using the class T as the function to run on the thread.
void add_thread (thread *thrd, int slot)
 Adds a thread to this group.
void remove_thread (boost::thread *thread)
 Removes a thread from the thread group.
void join_all ()
 calls "join()" on all the threads currently running and managed by this class.
void interrupt_all ()
 Calls interrupt() on all the threads being managed by this class.
size_t size ()
 Returns the total number of threads this class can manage.
void markThreadComplete (int slot)
 Sets a flag to mark a specific thread as having completed its execution.

Static Public Member Functions

static R3DThreadGroup::Pointer New (int maxThreads)
 Static new method which should be used to instantiate this class.

Protected Member Functions

 R3DThreadGroup (int maxThreads)
 Protected constructor as the Static New method should be use instead.


Constructor & Destructor Documentation

R3DThreadGroup::R3DThreadGroup ( int  maxThreads  )  [protected]

Protected constructor as the Static New method should be use instead.

Parameters:
maxThreads The maximum number of threads to run concurrently
Returns:


Member Function Documentation

R3DThreadGroup::Pointer R3DThreadGroup::New ( int  maxThreads  )  [static]

Static new method which should be used to instantiate this class.

Parameters:
maxThreads The maximum concurrent threads to allow at any given time
Returns:
boost::shared_ptr to the thread Group

int R3DThreadGroup::getMaxThreads (  ) 

Returns the maximum number of threads this group is managing.

Returns:

void R3DThreadGroup::setShouldDeleteThreadsOnDestruction ( bool  c  ) 

When this class is destroyed, the pointers to the actual thread objects will be 'delete'ed if this is set to TRUE.

The default for this class is a setting of true. If you set this value to true YOU WILL NEED TO properly cleanup the memory and resources used by the thread.

Parameters:
c 

int R3DThreadGroup::waitForOpenSlot (  ) 

Waits for an open slot to start another thread.

Returns:
The value of the open slot.

template<typename T>
boost::thread* R3DThreadGroup::startThread ( t  )  [inline]

Creates a new thread using the class T as the function to run on the thread.

Parameters:
t The function to run on the thread.
Returns:

void R3DThreadGroup::add_thread ( thread *  thrd,
int  slot 
)

Adds a thread to this group.

Parameters:
thrd The thread to add
slot The slot number to use

void R3DThreadGroup::remove_thread ( boost::thread *  thread  ) 

Removes a thread from the thread group.

Parameters:
thread The thread to remove from the thread group.

size_t R3DThreadGroup::size (  ) 

Returns the total number of threads this class can manage.

Returns:

void R3DThreadGroup::markThreadComplete ( int  slot  ) 

Sets a flag to mark a specific thread as having completed its execution.

Parameters:
slot 


The documentation for this class was generated from the following files:
Generated on Fri Aug 28 14:04:33 2009 for R3DImageTools by  doxygen 1.5.2