#include <ArThread.h>
Inheritance diagram for ArThread::
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 ArFunctor * | getFunc (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. |
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
|
|
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(). |
|
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. |