wibble  1.1
Public Member Functions | Protected Member Functions | List of all members
wibble::sys::Thread Class Referenceabstract

Encapsulates a thread. More...

#include <thread.h>

Inheritance diagram for wibble::sys::Thread:
Inheritance graph
[legend]

Public Member Functions

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

Protected Member Functions

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

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) {}
}
virtual void * main()=0
Main thread function, executed in the new thread after creation.

Constructor & Destructor Documentation

◆ ~Thread()

virtual wibble::sys::Thread::~Thread ( )
inlinevirtual

Member Function Documentation

◆ cancel()

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

Send a cancellation request to the thread.

References threadTag().

◆ detach()

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

Put the thread in the detached state.

References threadTag().

◆ join()

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

Join the thread.

References threadTag().

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

◆ kill()

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

Sent a signal to the thread.

References threadTag().

◆ main()

virtual void* wibble::sys::Thread::main ( )
protectedpure 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::Thread2, TestThread::Thread1, and wibble::sys::Pipe::Writer.

◆ start()

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

◆ startDetached()

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

Start the thread in the detached state.

References threadTag().

◆ testcancel()

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

Callback function used to start the thread.

◆ threadTag()

virtual const char* wibble::sys::Thread::threadTag ( )
inlineprotectedvirtual

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

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


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