cxxtools::DetachedThread Class Reference

Platform independent detached thread. More...

#include <cxxtools/thread.h>

Inheritance diagram for cxxtools::DetachedThread:
cxxtools::Thread cxxtools::NonCopyable

Public Member Functions

 DetachedThread (FuncPtrT fp)
- Public Member Functions inherited from cxxtools::Thread
virtual ~Thread ()
 Destructor.
State state () const
 Returns the current state of the thread.
void start ()
 Starts the thread.
void create ()

Protected Member Functions

 DetachedThread ()
 Constructs a detached thread.
virtual void destroy ()
 Destroys a detached thread.
virtual void run ()
 Thread entry method.
- Protected Member Functions inherited from cxxtools::Thread
 Thread ()
 Default Constructor.
 Thread (const Callable< void > &cb)
 Constructs a thread with a thread entry.
void init (const Callable< void > &cb)
 Initialize with a thread entry.
void detach ()
 Detaches the thread.
void join ()
 Joins the thread.
bool joinNoThrow ()
 Joins the thread.
void terminate ()
 Terminates the thread.
- Protected Member Functions inherited from cxxtools::NonCopyable
 NonCopyable ()

Additional Inherited Members

- Public Types inherited from cxxtools::Thread
enum  State { Ready = 0, Running = 1, Finished = 2 }
 Status of a thread. More...
- Static Public Member Functions inherited from cxxtools::Thread
static void exit ()
 Exits athread.
static void yield ()
 Yield CPU time.
static void sleep (const Milliseconds &ts)
 Sleep for some time.

Detailed Description

Platform independent detached thread.

A detached thread runs just for its own. The user does not need (actually can not even) wait for the thread to stop. The object is normally created on the heap.

Example:

class MyThread : public cxxtools::DetachedThread
{
protected:
void run();
};
{
// implement, whatever needs to be done in parallel
}
void someFunc()
{
MyThread *thread = new MyThread();
thread->start();
// here the thread runs and the program can do something
// else in parallel. It continues to run even after this
// function returns. The object is automatically destroyed,
// when the thread has finished.
}

Constructor & Destructor Documentation

cxxtools::DetachedThread::DetachedThread ( FuncPtrT  fp)
inlineexplicit
cxxtools::DetachedThread::DetachedThread ( )
inlineprotected

Constructs a detached thread.

Constructs a thread object to execute the virtual method run() when start() is called. DetachedThreads are always destructed by the virtual method destroy(). If objects of this class are created by new, destroy() must be overloaded ti call delete.

Member Function Documentation

virtual void cxxtools::DetachedThread::destroy ( )
inlineprotectedvirtual

Destroys a detached thread.

This method is called after the thread has finished. The default implementation uses delete to destruct this object.

virtual void cxxtools::DetachedThread::run ( )
inlineprotectedvirtual

Thread entry method.

This method is executed in a separate thread once start() is called. Override this method to implement a thread.


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