Yagl::Thread Class Reference

#include <thread.h>

Inheritance diagram for Yagl::Thread:

Yagl::BiDirectionalConnection Yagl::GlGfxKeyboard Yagl::ListeningConnection Yagl::SfxDevice List of all members.

Public Member Functions

 Thread ()
 Constructor.
virtual ~Thread ()
 Destructor.
virtual void * run ()
 the threaded method
bool start ()
 starts the thread
void stop ()
 stops the thread
void join ()
 joins the thread
void kill ()
 ungracefully stops a thread

Static Public Member Functions

static void yield ()
 yields the current thread
static void sleep (unsigned int msecs)
 sleeps for msecs

Protected Member Functions

 Thread (const Thread &thread)

Protected Attributes

THREAD_STATUS status_
 status of the thread see THREAD_STATUS enumeration

Detailed Description

Thread this is a generic Thread class that can be inherited from. it features simple methods to start, stop and join a thread. the inherited class only has to overwrite the run() method and call start to start the Thread


Constructor & Destructor Documentation

Yagl::Thread::Thread const Thread thread  )  [protected]
 

copy constructor hidden

Yagl::Thread::Thread  ) 
 

Constructor.

sets the members to initial states

virtual Yagl::Thread::~Thread  )  [virtual]
 

Destructor.

if the thread is runnin it will be ungracefully killed. it is recommended to use stop() before the destructor is called


Member Function Documentation

void Yagl::Thread::join  ) 
 

joins the thread

this method will join a thread. that means the thread that calls this method will be put to sleep until the joined thread has quit. this will never return if the thread does not quit.

void Yagl::Thread::kill  ) 
 

ungracefully stops a thread

this method will kill a thread explicitely not waiting for it to quit itself. only use this in exceptional situations where the thread has to be stoped. using this method can cause memory leaks and other nasty problems as the thread is interrupted and has no chance to clean up.

virtual void* Yagl::Thread::run  )  [virtual]
 

the threaded method

This method is the one that will be the thread. it can return a void* pointer but there's no mechanims yet to report that return value to a calling application if you inherit from this class this is the one method that has to be overwritten. as an implementor of this method you have to make sure to react on changes of the status_ member that will denote if the thread has to be stopped. in general, if status_ changes to THREAD_STATUS::STOP then make sure to exit the thread ( with cleaning up what needs cleanup of course )

Reimplemented in Yagl::SfxDevice, Yagl::GlGfxKeyboard, Yagl::BiDirectionalConnection, and Yagl::ListeningConnection.

static void Yagl::Thread::sleep unsigned int  msecs  )  [static]
 

sleeps for msecs

this is a static method that gives the user the possibility to put the current thread to sleep. the thread will not execute for msecs and give processing time to other threads and processes by this.

Parameters:
msecs number of milliseconds to put the current thread to sleep

bool Yagl::Thread::start  ) 
 

starts the thread

this will start the threads main function if it is not already running

void Yagl::Thread::stop  ) 
 

stops the thread

this method will stop the thread by setting status_ to STOP and then join the thread. thus it will wait until the thread exited. make sure that you exit within the run method if status_ is set to STOP or this method will wait forever.

static void Yagl::Thread::yield  )  [static]
 

yields the current thread

this is a static method ( that is not associated with a Thread instance ) that gives the user the possibility to yield. yielding means that the scheduler of the os is told to schedule another thread other than the current thread you can call this from wherever you want in order to give more processing time to other processses and threads


The documentation for this class was generated from the following file:
Generated on Tue Jan 10 15:42:38 2006 for YAGL - yet another gameprogramming library by  doxygen 1.4.5