Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

BasicThread Class Reference

There are two was to use this class. More...

#include <BasicThread.h>

Inheritance diagram for BasicThread:

Inheritance graph
[legend]
Collaboration diagram for BasicThread:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 BasicThread ()
 BasicThread (BasicFunctorBase *functor)
 BasicThread (void *(*startRoutine)(void *))
virtual ~BasicThread ()
virtual void run ()
 This virtual function should be overriden by inheriting process.
bool start ()
 Starts the thread.
void stop ()
 Requests the thread stop via the shutdown variable.
bool join ()
 This causes the calling thread of execution to block until the thread of this object exits.
bool cancel ()
bool detach ()
void * getData ()
void setData (void *data)
void setRunning (bool x)
 This function is not always necessary.
bool isRunning ()
bool shouldShutdown ()
 This function should be called from the thread itself to determine if shutdown has been requested.

Static Public Member Functions

void testCancel ()

Protected Attributes

bool shutdown
bool running

Private Member Functions

virtual void onExit ()
 This virtual function can be overriden by inheriting classes which would like to do some extra processing on thread exit.
virtual void onEntrance ()
 This virtual function can be overriden by inheriting classes which would like to do some extra processing before thread startup.
void init ()
 This function does initializations common to all the constructors.

Static Private Member Functions

void * starter (void *me)
 This static function should never be called directly.

Private Attributes

pthread_t thread
pthread_attr_t attr
BasicFunctorBasefunctor
void *(* startRoutine )(void *)
void * data

Detailed Description

There are two was to use this class.

  1. A class can inherit from BasicThread and implement the the virtual run() function. This alows the object to have its own thread of execution.
  2. A user can instantiate BasicThread passing in a pointer to a void *startRoutine(void *). When the start function of of the thread object is called the startRoutine will be called with a new thread of execution.

The user has the ability to set a data variable which will be passed to the user function. This void * is set to point to the BasicThread object itself by default. This gives the user the ability to communicate data to the thread without using global data.


Constructor & Destructor Documentation

BasicThread::BasicThread  ) 
 

BasicThread::BasicThread BasicFunctorBase functor  ) 
 

BasicThread::BasicThread void *(*  startRoutine)(void *)  ) 
 

BasicThread::~BasicThread  )  [virtual]
 


Member Function Documentation

bool BasicThread::cancel  ) 
 

bool BasicThread::detach  ) 
 

void* BasicThread::getData  )  [inline]
 

void BasicThread::init  )  [private]
 

This function does initializations common to all the constructors.

It takes in a special consideration for SunOS to circumvent a bug that occurs when more then one thread is started.

bool BasicThread::isRunning  )  [inline]
 

bool BasicThread::join  ) 
 

This causes the calling thread of execution to block until the thread of this object exits.

void BasicThread::onEntrance  )  [private, virtual]
 

This virtual function can be overriden by inheriting classes which would like to do some extra processing before thread startup.

It is called by BasicThread just before either the overriden run() or startRoutine function is called.

void BasicThread::onExit  )  [private, virtual]
 

This virtual function can be overriden by inheriting classes which would like to do some extra processing on thread exit.

It is called by BasicThread just after either the overriden run() or startRoutine function returns.

void BasicThread::run  )  [virtual]
 

This virtual function should be overriden by inheriting process.

This function is called by BasicThread from within the new thread of execution after start() is called.

void BasicThread::setData void *  data  )  [inline]
 

void BasicThread::setRunning bool  x  )  [inline]
 

This function is not always necessary.

When a thread starts up it will automaticly set running to true. However if you are starting a group of threads this function is useful so the starting threads don't mistakenly think a thread has exited when it is actually just starting up. Before starting any threads in the group they can all be set to started. This gives the alusion that all the threads started at once.

Parameters:
x True or False

bool BasicThread::shouldShutdown  ) 
 

This function should be called from the thread itself to determine if shutdown has been requested.

If a thread doesn't monitor this variable stop() will not work!

Returns:
True if shutdown has been requested

bool BasicThread::start  ) 
 

Starts the thread.

void * BasicThread::starter void *  me  )  [static, private]
 

This static function should never be called directly.

It is used by pthreads in starting the thread.

Parameters:
me A this pointer
Returns:
Nothing

void BasicThread::stop  ) 
 

Requests the thread stop via the shutdown variable.

There is however no guarantee that the thread will actually stop. The running thread must check the shutdown variable and decide to stop.

void BasicThread::testCancel  )  [static]
 


Member Data Documentation

pthread_attr_t BasicThread::attr [private]
 

void* BasicThread::data [private]
 

BasicFunctorBase* BasicThread::functor [private]
 

bool BasicThread::running [protected]
 

bool BasicThread::shutdown [protected]
 

void*(* BasicThread::startRoutine)(void *) [private]
 

pthread_t BasicThread::thread [private]
 


The documentation for this class was generated from the following files:
Generated on Thu Sep 16 16:17:23 2004 for nostdinc by doxygen 1.3.8