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

ArASyncTask Class Reference

Asynchronous task (runs in its own thread). More...

#include <ArASyncTask.h>

Inheritance diagram for ArASyncTask:

ArThread ArFunctorASyncTask ArRecurrentTask ArSignalHandler ArSoundsQueue List of all members.

Public Member Functions

 ArASyncTask ()
 Constructor.
virtual int create (bool joinable=true, bool lowerPriority=true)
 Create the task and start it going.
virtual void run (void)
 Run in this thread.
virtual void runAsync (void)
 Run in its own thread.
virtual void * runInThisThread (void *arg=0)
 Run the code of the task syncronously.
virtual void * runThread (void *arg)=0
 The main run loop.
virtual void stopRunning (void)
 Stop the thread.
virtual ~ArASyncTask ()
 Destructor.

Detailed Description

Asynchronous task (runs in its own thread).

The ArAsynTask is a task that runs in its own thread. This is a rather simple class. The user simply needs to derive their own class from ArAsyncTask and define the runThread() function. They then need to create an instance of their task and call run or runAsync. The standard way to stop a task is to call stopRunning() which sets ArThread::myRunning to false. In their run loop, they should pay attention to the getRunning() or the ArThread::myRunning variable. If this value goes to false, the task should clean up after itself and exit its runThread() function.

Definition at line 49 of file ArASyncTask.h.


Member Function Documentation

void * ArASyncTask::runInThisThread void *  arg = 0  )  [virtual]
 

Run the code of the task syncronously.

This will run the code of the ArASyncTask without creating a new thread to run it in. It performs the needed setup then calls runThread(). This is good if you have a task which you wish to run multiple instances of and you want to use the main() thread instead of having it block, waiting for exit of the program.

Parameters:
arg the argument to pass to the runThread()

Definition at line 59 of file ArASyncTask.cpp.

References ArMutex::lock(), ArLog::log(), runThread(), and ArMutex::unlock().

Referenced by ArSoundsQueue::run(), and run().

virtual void* ArASyncTask::runThread void *  arg  )  [pure virtual]
 

The main run loop.

Override this function and put your taskes run loop here. Check the value of getRunning() or myRunning periodicly in your loop. If the value goes false, the loop should exit and runThread() should return.

Implemented in ArFunctorASyncTask, ArRecurrentTask, ArSignalHandler, and ArSoundsQueue.

Referenced by runInThisThread().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:43 2005 for Aria by  doxygen 1.4.0