gxThread Class Reference

Encapsulates a native thread on the platform. More...

#include <gxThread.h>

Inheritance diagram for gxThread:

gxThreadSafeObject List of all members.

Public Types

enum  priority_t {
  PRIORITY_IDLE, PRIORITY_LOWEST, PRIORITY_BELOW_NORMAL, PRIORITY_NORMAL,
  PRIORITY_ABOVE_NORMAL, PRIORITY_HIGHEST, PRIORITY_TIME_CRITICAL
}
 Thread priority levels. More...
enum  states_t { STATE_STOPPED = 0, STATE_STARTING = 1, STATE_STARTED = 2, STATE_STOPPING = 3 }

Public Member Functions

 gxThread (gxThreadRunnable *runnable, priority_t priority=PRIORITY_NORMAL)
virtual ~gxThread ()
void start (bool wait=true)
 Start the thread.
void stop ()
 Stops the thread by invoking "stopRequest" and then waiting for the thread to terminate.
virtual void run ()
 Override to provide the code which will execute within the thread.
virtual void onStopThreadRequest ()
 This overridable method is invoked when the caller invokes stop.
bool isStopping ()
 Specifies whether a stop request is pending.
states_t getState ()
 Returns the threads start/stop state.

Static Public Member Functions

static void sleep (long milliseconds)
 Causes the current thread to sleep for the specified number of milliseconds.

Detailed Description

Encapsulates a native thread on the platform.

To use this class effectively, you must implement a "run" method containing the code to be executed in the thread. The run method may be implemented in a subclass of gxThread by overriding the existing run method. Alternatively, the run method may be implemented in another class, providing that class implements the gxThreadRunnable interface and overrides the pure virtual run method.


Member Enumeration Documentation

enum gxThread::priority_t
 

Thread priority levels.

These names look suspiciously similar to the Win32 thread priorities, but don't count on them having the same value.

Enumerator:
PRIORITY_IDLE 
PRIORITY_LOWEST 
PRIORITY_BELOW_NORMAL 
PRIORITY_NORMAL 
PRIORITY_ABOVE_NORMAL 
PRIORITY_HIGHEST 
PRIORITY_TIME_CRITICAL 

enum gxThread::states_t
 

Enumerator:
STATE_STOPPED 
STATE_STARTING 
STATE_STARTED 
STATE_STOPPING 


Constructor & Destructor Documentation

gxThread::gxThread gxThreadRunnable runnable,
priority_t  priority = PRIORITY_NORMAL
 

virtual gxThread::~gxThread  )  [virtual]
 


Member Function Documentation

states_t gxThread::getState  ) 
 

Returns the threads start/stop state.

bool gxThread::isStopping  ) 
 

Specifies whether a stop request is pending.

virtual void gxThread::onStopThreadRequest  )  [virtual]
 

This overridable method is invoked when the caller invokes stop.

The default implementation just notifies this object. The thread can invoke the isStopping method to determine whether the most recent notification was caused by "stop". If so, the thread should exit the run method so that the application does not stall.

virtual void gxThread::run  )  [virtual]
 

Override to provide the code which will execute within the thread.

This method will *not* execute if a gxThreadRunnable was provided in the constructor.

static void gxThread::sleep long  milliseconds  )  [static]
 

Causes the current thread to sleep for the specified number of milliseconds.

void gxThread::start bool  wait = true  ) 
 

Start the thread.

If wait is true, then wait until the thread has actually started.

void gxThread::stop  ) 
 

Stops the thread by invoking "stopRequest" and then waiting for the thread to terminate.

The precise shutdown mechanism is provided by the specific implementation of "run" and "stopRequest".


The documentation for this class was generated from the following file:
Generated on Mon Nov 21 01:01:37 2005 for gxLib by  doxygen 1.4.5