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

rwil::Thread Class Reference

Creates a thread which allows one instance of a thread at a time to execute. More...

#include <Synchronization.h>

Inheritance diagram for rwil::Thread::

rwil::RWIL List of all members.

Public Methods

 Thread ()
 Constructs a thread. More...

virtual ~Thread ()
 Destructs a thread. More...

void Start ()
 Start the thread. More...

void Go ()
 Begins the execution of the function in THIS thread. More...

void Join ()
 Join the thread. More...


Protected Methods

void Yield ()
 Yield timeslice. More...

virtual void Function ()=0
 This is the function that implements the thread of execution. More...


Protected Attributes

Mutex m_mutex
 Mutex used to ensure that this is only executing one thread of execution. More...


Detailed Description

Creates a thread which allows one instance of a thread at a time to execute.

This class encapsulates a single thread of execution. Call Start() to start the thread.

Definition at line 160 of file Synchronization.h.


Constructor & Destructor Documentation

rwil::Thread::Thread  
 

Constructs a thread.

Essentially does nothing.

Definition at line 199 of file Synchronization.cpp.

00199 {}

rwil::Thread::~Thread   [virtual]
 

Destructs a thread.

Ensures that the mutex is not held anymore.

Definition at line 200 of file Synchronization.cpp.

References m_mutex.

00201   {
00202     m_mutex.Release();
00203   }


Member Function Documentation

virtual void rwil::Thread::Function   [protected, pure virtual]
 

This is the function that implements the thread of execution.

This function must be implemented by all deriving classes.

Reimplemented in rwil::RWIL.

Referenced by Go().

void rwil::Thread::Go  
 

Begins the execution of the function in THIS thread.

This function is used internally to start execution in the new thread of execution.

Definition at line 214 of file Synchronization.cpp.

References Function(), and m_mutex.

00215   {
00216     Function();
00217     m_mutex.Release();
00218   }

void rwil::Thread::Join  
 

Join the thread.

Wait for the thread to finish.

Definition at line 229 of file Synchronization.cpp.

References NULL.

00230   {
00231     if(pthread_join(m_threadHandle, NULL))
00232       assert(0);
00233   }

void rwil::Thread::Start  
 

Start the thread.

Begins the thread of execution. Ensures that this thread does not start again until this one dies.

Definition at line 204 of file Synchronization.cpp.

References m_mutex, and NULL.

00205   {
00206     m_mutex.Wait();
00207 #ifdef _WIN32
00208     m_threadHandle = beginthread(StartThread, 0, this);
00209 #endif
00210 #ifdef LINUX
00211     pthread_create(&m_threadHandle, NULL, StartThread, this);
00212 #endif
00213   }

void rwil::Thread::Yield   [protected]
 

Yield timeslice.

This should be used inside of the thread instead of something os-dependent.

Definition at line 220 of file Synchronization.cpp.

00221   {
00222 #ifdef _WIN32
00223     Sleep(0);
00224 #endif
00225 #ifdef LINUX
00226     sched_yield();
00227 #endif  
00228   }


Member Data Documentation

Mutex rwil::Thread::m_mutex [protected]
 

Mutex used to ensure that this is only executing one thread of execution.

Reimplemented in rwil::RWIL.

Definition at line 201 of file Synchronization.h.

Referenced by Go(), Start(), and ~Thread().


The documentation for this class was generated from the following files:
Generated on Tue Apr 9 13:53:09 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001