Thread Class Reference

#include <thread.h>

List of all members.

Public Member Functions

 Thread (ThreadRunFunction func=0, void *arg=0, bool start_thread=true, bool autodelete=false)
 Create a thread.
virtual ~Thread ()
 Destroy a thread.
void start ()
 Start a thread.
void stop ()
 Ask a thread to stop running.
bool join ()
 Block until the thread stops running.
bool checkForStop ()
 Threads may call checkForStop() periodically to check if they've been asked to stop.
virtual void run (void *arg=0)
 Run the Thread's entry point function.
bool isAlive ()
 Returns true if the thread is running.
U32 getId ()
 Returns the platform specific thread id for this thread.

Public Attributes

bool autoDelete
 If set, the thread will delete itself once it has finished running.

Protected Attributes

PlatformThreadData * mData
bool shouldStop
 Used to signal threads need to stop.


Constructor & Destructor Documentation

Thread::Thread ( ThreadRunFunction  func = 0,
void arg = 0,
bool  start_thread = true,
bool  autodelete = false 
)

Create a thread.

Parameters:
func The starting function for the thread.
arg Data to be passed to func, when the thread starts.
start_thread Whether to start the Thread immediately.

virtual Thread::~Thread (  )  [virtual]

Destroy a thread.

The thread MUST be allowed to exit before it is destroyed.


Member Function Documentation

void Thread::start (  ) 

Start a thread.

Sets shouldStop to false and calls run() in a new thread of execution.

void Thread::stop (  )  [inline]

Ask a thread to stop running.

bool Thread::join (  ) 

Block until the thread stops running.

bool Thread::checkForStop (  )  [inline]

Threads may call checkForStop() periodically to check if they've been asked to stop.

As soon as checkForStop() returns true, the thread should clean up and return.

virtual void Thread::run ( void arg = 0  )  [virtual]

Run the Thread's entry point function.

Override this method in a subclass of Thread to create threaded code in an object oriented way, and without passing a function ptr to Thread(). Also, you can call this method directly to execute the thread's code in a non-threaded way.

bool Thread::isAlive (  ) 

Returns true if the thread is running.

U32 Thread::getId (  ) 

Returns the platform specific thread id for this thread.


Member Data Documentation

PlatformThreadData* Thread::mData [protected]

bool Thread::shouldStop [protected]

Used to signal threads need to stop.

Threads set this flag to false in start()

If set, the thread will delete itself once it has finished running.