CVR-Lib last update 20 Sep 2009

cvr::thread Class Reference

CVR-Lib thread class. More...

#include <cvrThread.h>

Inherited by cvr::guiServer::guiServer::guiThread.

Collaboration diagram for cvr::thread:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 thread ()
virtual ~thread ()
virtual void start ()
virtual void stop ()
virtual void join ()
bool isAlive () const
bool representsCalledThread () const

Protected Member Functions

virtual void run ()=0
virtual void cleanUp ()


Detailed Description

CVR-Lib thread class.

Representiation of a system thread (currently a posix thread for Unix systems, and WIN32 thread for windows systems)

If you need a thread, just inherit from this class and reimplement the method run():

 class myThread : public thread {
 protected:
   void run() {
     // your thread's job here!
   }
 };

 ...

 // somewhere else in your code:

 myThread aThread;
 aThread.start(); // do your threads job...
 // continue with other things (your thread runs in parallel...)

Constructor & Destructor Documentation

cvr::thread::thread (  ) 

Default constructor.

virtual cvr::thread::~thread (  )  [virtual]

Destructor.

If the thread is still executing while destroying the thread object, the thread will be forced to stop. Use join() to wait for the thread to terminate itself.


Member Function Documentation

virtual void cvr::thread::cleanUp (  )  [inline, protected, virtual]

Clean up the thread.

Method to be called when finishing regulary or cancelling the thread; something like a destructor for the run() method.

The default behaviour, if not overloaded, is do nothing.

bool cvr::thread::isAlive (  )  const

Check if thread is alive.

Test if the thread that should execute the run() method is still alive.

Returns:
true if the thread is alive, or false if it was already stopped or finished.

virtual void cvr::thread::join (  )  [virtual]

Wait for thread termination.

This has to be called by a thread different than the one executing the run() method, in order to wait that the run() method normally finishes.

bool cvr::thread::representsCalledThread (  )  const

Check which thread is calling.

Returns whether the thread that calls this method represents the thread executing the run() method (i.e. if the method is directly or indirectly called within the run() method).

Returns:
true if the thread executing the run() method is the one that called the current method, or false otherwise.

virtual void cvr::thread::run (  )  [protected, pure virtual]

Thread execution method.

The whole thread object is somehow just a representation for this method, since the created thread will just call it, (which means will execute the overloaded run() method of the derived class). The thread will also persist as long as this method does, i.e. the thread will stop when the method finishes.

virtual void cvr::thread::start (  )  [virtual]

Start thread.

This method is called by the parent thread, to start in a second thread the execution of the run() method, which is overloaded in the derived classes.

virtual void cvr::thread::stop (  )  [virtual]

Stop thread execution.

Forces the thread to stop executing.

Overload this function to cleanup things that the run() method could leave unfinished after thread cancellation.


The documentation for this class was generated from the following file:

Generated on Sun Sep 20 22:09:06 2009 for CVR-Lib by Doxygen 1.5.8