wibble
1.1
|
Encapsulates a thread. More...
#include <thread.h>
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... | |
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:
|
inlinevirtual |
void wibble::sys::Thread::cancel | ( | ) |
Send a cancellation request to the thread.
References threadTag().
void wibble::sys::Thread::detach | ( | ) |
Put the thread in the detached state.
References threadTag().
void * wibble::sys::Thread::join | ( | ) |
Join the thread.
References threadTag().
Referenced by TestThread::execution(), and TestThread::sharedMemory().
void wibble::sys::Thread::kill | ( | int | signal) |
Sent a signal to the thread.
References threadTag().
|
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 wibble::sys::Pipe::Writer, TestThread::Thread2, and TestThread::Thread1.
void wibble::sys::Thread::start | ( | ) |
Start the thread.
References threadTag().
Referenced by TestThread::execution(), wibble::sys::Pipe::Writer::run(), and TestThread::sharedMemory().
void wibble::sys::Thread::startDetached | ( | ) |
Start the thread in the detached state.
References threadTag().
|
protected |
Callback function used to start the thread.
|
inlineprotectedvirtual |