Thread Class Reference

Simplistic posix thread class. More...

#include <thread.h>

Inheritance diagram for Thread:

DMMClass Escort97 GDM703 M9803R MetexAscii PeakTech10Ascii VC820 IOCBUVMonitor Metex14BytesContinuous Metex14BytesPolling Metex15BytesContinuous List of all members.

Public Member Functions

 Thread ()
virtual ~Thread ()
int start ()
 Start the thread.
void wait ()
 Wait for the thread to finish (no timeout!).
void stop ()
 Gracefully stop the thread.
void quit ()
 Forcibly stop thread.
bool running () const
 Is the thread running?

Protected Member Functions

virtual void run ()=0
 The thread mainloop.

Protected Attributes

bool m_run
pthread_t m_pthread

Static Private Member Functions

static void * start_thread (void *)

Detailed Description

Simplistic posix thread class.

To create a threaded object derive from this class and implement the run member function. Check as often as you can the m_run member variable and immediately return from the function if it is set to false.

Yes, I know that there are numerous libraries that do the same and better. But I find it essential to keep the dependencies as low as possible for thin clients.

Definition at line 36 of file thread.h.

Constructor & Destructor Documentation

Thread::Thread  ) 


Definition at line 22 of file thread.cpp.

Thread::~Thread  )  [virtual]


Definition at line 26 of file thread.cpp.

Member Function Documentation

void Thread::quit  ) 

Forcibly stop thread.

Not recommended as this might leak resources

Definition at line 52 of file thread.cpp.

virtual void Thread::run  )  [protected, pure virtual]

The thread mainloop.

This pure virtual function has to be implemented by the thread. Put your mainloop in here. Frequently check the m_run flag. If false immediately return.

See also:
m_run running

Implemented in DMMClass, Escort97, GDM703, M9803R, MetexAscii, PeakTech10Ascii, and VC820.

Referenced by start_thread().

bool Thread::running  )  const [inline]

Is the thread running?

Definition at line 62 of file thread.h.

References m_run.

int Thread::start  ) 

Start the thread.

pthread_create return code

Definition at line 39 of file thread.cpp.

References m_pthread, m_run, and start_thread().

Referenced by MetexAscii::MetexAscii(), MetexAscii::run(), and GDM703::run().

void * Thread::start_thread void *   )  [static, private]

pthreads need a "C" compatible function pointer. This static function wraps the class member run.

Definition at line 30 of file thread.cpp.

References run().

Referenced by start().

void Thread::stop  )  [inline]

Gracefully stop the thread.

Definition at line 54 of file thread.h.

References m_run.

void Thread::wait  ) 

Wait for the thread to finish (no timeout!).

Definition at line 47 of file thread.cpp.

References m_pthread.

Member Data Documentation

pthread_t Thread::m_pthread [protected]

Definition at line 66 of file thread.h.

Referenced by start(), and wait().

bool Thread::m_run [protected]

Definition at line 65 of file thread.h.

Referenced by VC820::run(), PeakTech10Ascii::run(), MetexAscii::run(), M9803R::run(), GDM703::run(), Escort97::run(), running(), start(), and stop().

The documentation for this class was generated from the following files:
Generated on Mon Jan 22 23:24:19 2007 for cdmm by  doxygen 1.4.6