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

ExecutionThread Class Reference

Represents a thread in a multithreaded application. More...

#include <thread.h>

Collaboration diagram for ExecutionThread:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ExecutionThread ()
 Constructor; actually does nothing :).

virtual ~ExecutionThread ()
int start ()
 Start a new thread and have it execute the function run().

bool running ()
 See if the thread is currently running or not.


Protected Member Functions

virtual void run ()
void exit ()
void yield ()

Private Member Functions

 ExecutionThread (const ExecutionThread &)
 Do not use these:.

void operator= (const ExecutionThread &)

Private Attributes

ThreadKernel::TNodehandle

Friends

class ThreadKernel

Detailed Description

Represents a thread in a multithreaded application.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
I chose to call it ExecutionThread since plain "Thread" seemd too general to me :)

In order to make use of this class, you must derive a class from this one and override the virtual function run(). To start the thread, call start(); this will execute run() in a new thread. When run() returns, or the thread calls exit(), the thread exits. The object itself, however, will remain existant and you can re-start a new thread using start().

Note:
Before using any threads, initialize the thread system using ExecutionThread::init() (static member). This should be called from the main execution thread.
There is currently no way to "kill" (i.e. "cancel") threads. It is probably better (and easier) to do higher-leverl cooperative communication then using cancellation because in the latter case one has to pay much attention on proper resource release.

Definition at line 158 of file thread.h.


Constructor & Destructor Documentation

ExecutionThread::ExecutionThread const ExecutionThread  )  [private]
 

Do not use these:.

ExecutionThread::ExecutionThread  ) 
 

Constructor; actually does nothing :).

Definition at line 268 of file thread.cc.

References handle.

ExecutionThread::~ExecutionThread  )  [virtual]
 

Destructor: It is legal to destroy a thread if it is still running. In this case, the thread will continue to run until it exits normally.

Definition at line 273 of file thread.cc.

References ThreadKernel::unregister().


Member Function Documentation

void ExecutionThread::exit  )  [protected]
 

This must be called from within the running thread if it wishes to to exit. (This is like returning from run()).

Definition at line 247 of file thread.cc.

void ExecutionThread::operator= const ExecutionThread  )  [private]
 

void ExecutionThread::run  )  [protected, virtual]
 

This is executed by the new thread; in order for this class to be useful, you should override this function.

Definition at line 259 of file thread.cc.

Referenced by ThreadKernel::_ThreadFuncWrapper().

bool ExecutionThread::running  )  [inline]
 

See if the thread is currently running or not.

If you successfully started a thread before and it is not running then that means that the thread finished.

Definition at line 218 of file thread.h.

References handle.

int ExecutionThread::start  ) 
 

Start a new thread and have it execute the function run().

Note that the start function itself is not thread-safe; this means you must not call this start() simultaniously from several threads; in case you get such situations, protect the ExecutionThread with a mutex.

It is guaranteed that there is no "dead time" between the return of start() and when running() becomes true. If running() is false the first time (or any time) you call it after start(), it means that the thread already exited.

Returns:
0 -> OK -2 -> thread already running (oops?!; try not to provoke that) ... -> thread creation failure

Todo:
Thread creation failure error reporting. (really do it?)

We must "wait" until the ThreadManager knows of the new thread, i.e. the new thread executed the wrapper function. This is just a few CPU instructions and hence a single yield should be enough.

Definition at line 215 of file thread.cc.

References handle.

void ExecutionThread::yield  )  [protected]
 

This can be called from within the running thread to give way to other threads waiting to be scheduled. Normally not needed!

Definition at line 253 of file thread.cc.


Friends And Related Function Documentation

friend class ThreadKernel [friend]
 

Definition at line 160 of file thread.h.


Member Data Documentation

ThreadKernel::TNode* ExecutionThread::handle [private]
 

Internal thread structure as allocated by the ThreadKernel. If this is NULL, the thread is not running, if non-NULL, it points to ThreadKernel's internal handle for the thread.

Definition at line 165 of file thread.h.

Referenced by ThreadKernel::_PhookNotifier(), ThreadKernel::_ThreadFuncWrapper(), ThreadKernel::_unregister(), ExecutionThread(), running(), and start().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:24 2005 for Ray by doxygen 1.3.5