Main Page   Class Hierarchy   Compound List   Compound Members  

ArThread Class Reference

POSIX/WIN32 thread wrapper class. More...

#include <ArThread.h>

Inheritance diagram for ArThread::

ArASyncTask ArRangeDeviceThreaded ArRecurrentTask ArSignalHandler ArSick List of all members.

Public Types

enum  Status {
  STATUS_FAILED = 1, STATUS_NORESOURCE, STATUS_NO_SUCH_THREAD, STATUS_INVALID,
  STATUS_JOIN_SELF, STATUS_ALREADY_DETATCHED
}

Public Methods

 ArThread (bool blockAllSignals=true)
 Constructor.

 ArThread (ThreadType thread, bool joinable, bool blockAllSignals=true)
 Constructor - starts the thread.

 ArThread (ArFunctor *func, bool joinable=true, bool blockAllSignals=true)
 Constructor - starts the thread.

virtual ~ArThread (void)
 Destructor.

virtual int create (ArFunctor *func, bool joinable=true, bool lowerPriority=true)
 Create and start the thread.

virtual void stopRunning (void)
 Stop the thread.

virtual int join (void **ret=NULL)
 Join on the thread.

virtual int detach (void)
 Detatch the thread so it cant be joined.

virtual void cancel (void)
 Cancel the thread.

virtual bool getRunning (void)
 Get the running status of the thread.

virtual bool getRunningWithLock (void)
 Get the running status of the thread, locking around the variable.

virtual bool getJoinable (void)
 Get the joinable status of the thread.

virtual ThreadType * getThread (void)
 Get the underlying thread type.

virtual ArFunctorgetFunc (void)
 Get the functor that the thread runs.

virtual void setRunning (bool yesno)
 Set the running value on the thread.

int lock (void)
 Lock the thread instance.

int tryLock (void)
 Try to lock the thread instance without blocking.

int unlock (void)
 Unlock the thread instance.

std::string getError (int err)
 Translate error into string.

bool getBlockAllSignals (void)
 Do we block all process signals at startup?


Static Public Methods

void init (void)
 Initialize the internal book keeping structures. More...

ArThread * self (void)
 Returns the instance of your own thread. More...

void stopAll ()
 Stop all threads.

void cancelAll (void)
 Cancel all threads.

void joinAll (void)
 Join on all threads.

void yield (void)
 Yield the processor to another thread.


Protected Attributes

bool myRunning
 State variable to denote when the thread should continue or exit.


Detailed Description

POSIX/WIN32 thread wrapper class.

create() will create the thread. That thread will run the given Functor.

A thread can either be in a detached state or a joinable state. If the thread is in a detached state, that thread can not be join()'ed upon. The thread will simply run until the program exits, or its function exits. A joinable thread means that another thread and call join() upon it. If this function is called, the caller will block until the thread exits its function. This gives a way to synchronize upon the lifespan of threads.

Calling cancel() will cancel the thread.

The static function self() will return a thread


Member Enumeration Documentation

enum ArThread::Status
 

Enumeration values:
STATUS_FAILED  Failed to create the thread.
STATUS_NORESOURCE  Not enough system resources to create the thread.
STATUS_NO_SUCH_THREAD  The thread can no longer be found.
STATUS_INVALID  Thread is detached or another thread is joining on it.
STATUS_JOIN_SELF  Thread is your own thread. Can't join on self.
STATUS_ALREADY_DETATCHED  Thread is already detatched.


Member Function Documentation

void ArThread::init void    [static]
 

Initialize the internal book keeping structures.

Initializes the internal structures which keep track of what thread is what. This is called by Aria::init(), so the user will not normaly need to call this function themselves. This funtion *must* be called from the main thread of the application. In otherwords, it should be called by main().

ArThread * ArThread::self void    [static]
 

Returns the instance of your own thread.

If a newly created thread calls self() on itself too soon, this will return NULL. This is due to the fact that the thread is first created and started. Then the operating system returns the thread ID and thread that called create() then updates the list of threads with the new thread ID. There is just not much that can be done about that. The use should be aware of this caveat.


The documentation for this class was generated from the following files:
Generated on Tue Nov 12 17:44:07 2002 for Aria by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001