wibble::sys::Thread Class Reference

#include <thread.h>

Inheritance diagram for wibble::sys::Thread:

Inheritance graph
[legend]

List of all members.


Detailed Description

Encapsulates a thread.

FIXME: C++ resource management and thread cancellation C++ uses the "resource allocation is instantiation" way of managing resources: when a function exits, either by terminating or because an exception has been raised, destructors are called.

However, when a thread is canceled, the flow of control is interrupted and no exceptions are thrown. Cleanup should be performed by registering cleanup functions, but a cleanup function can't usefully throw exceptions nor call destructors. At the moment, I don't know what to do to correctly release resources on thread cancellation. I'm waiting for new ideas.

The current way out is not to use cancelation, but explicitly set some boolean exit condition:

         class MyThread
         {
             bool interrupted;
             void* main()
             {
                // do things
                if (interrupted)
                    throw MyInterruptedException();
                // do things
                while (!interrupted)
                {
                   // do things
                }
             }
             MyThread() : interrupted(false) {}
         }

Public Member Functions

virtual ~Thread ()
void start ()
 Start the thread.
void startDetached ()
 Start the thread in the detached state.
void * join ()
 Join the thread.
void detach ()
 Put the thread in the detached state.
void cancel ()
 Send a cancellation request to the thread.
void kill (int signal)
 Sent a signal to the thread.

Protected Member Functions

virtual const char * threadTag ()
 Short tag describing this thread, used in error messages and identification.
virtual void * main ()=0
 Main thread function, executed in the new thread after creation.
void testcancel ()

Static Protected Member Functions

static void * Starter (void *parm)
 Callback function used to start the thread.

Protected Attributes

pthread_t thread

Constructor & Destructor Documentation

virtual wibble::sys::Thread::~Thread (  )  [inline, virtual]


Member Function Documentation

virtual const char* wibble::sys::Thread::threadTag (  )  [inline, protected, virtual]

Short tag describing this thread, used in error messages and identification.

Referenced by cancel(), detach(), join(), kill(), start(), and startDetached().

virtual void* wibble::sys::Thread::main (  )  [protected, pure virtual]

Main thread function, executed in the new thread after creation.

When main() exits, the new thread ends and main() result will be the thread exit result

Implemented in TestThread::Thread1, and TestThread::Thread2.

void * wibble::sys::Thread::Starter ( void *  parm  )  [static, protected]

Callback function used to start the thread.

Referenced by start(), and startDetached().

void wibble::sys::Thread::testcancel (  )  [protected]

void wibble::sys::Thread::start (  ) 

Start the thread.

References Starter(), thread, and threadTag().

Referenced by TestThread::execution(), and TestThread::sharedMemory().

void wibble::sys::Thread::startDetached (  ) 

Start the thread in the detached state.

References Starter(), thread, and threadTag().

void * wibble::sys::Thread::join (  ) 

Join the thread.

References thread, and threadTag().

Referenced by TestThread::execution(), and TestThread::sharedMemory().

void wibble::sys::Thread::detach (  ) 

Put the thread in the detached state.

References thread, and threadTag().

void wibble::sys::Thread::cancel (  ) 

Send a cancellation request to the thread.

References thread, and threadTag().

void wibble::sys::Thread::kill ( int  signal  ) 

Sent a signal to the thread.

References thread, and threadTag().


Member Data Documentation

pthread_t wibble::sys::Thread::thread [protected]


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

Generated on Tue Mar 11 11:26:34 2008 for wibble by  doxygen 1.5.5