wibble::sys::Thread Class Referenceabstract

Encapsulates a thread. More...

`#include <thread.h>`

Inheritance diagram for wibble::sys::Thread:
[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) {}
}

## Constructor & Destructor Documentation

## ~Thread()

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

inline virtual

References cancel(), detach(), join(), kill(), start(), and startDetached().

## Member Function Documentation

## cancel()

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

Send a cancellation request to the thread.

References threadTag().

Referenced by ~Thread().

## detach()

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

Put the thread in the detached state.

References threadTag().

Referenced by ~Thread().

## join()

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

Join the thread.

References threadTag().

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

## kill()

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

Sent a signal to the thread.

References threadTag().

Referenced by ~Thread().

## main()

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 wibble::sys::Pipe::Writer, TestThread::Thread2, and TestThread::Thread1.

Referenced by threadTag(), and wibble::sys::usleep().

## start()

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

Start the thread.

References threadTag().

Referenced by TestThread::execution(), wibble::sys::Pipe::Writer::run(), TestThread::sharedMemory(), and ~Thread().

## startDetached()

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

Start the thread in the detached state.

References threadTag().

Referenced by ~Thread().

## testcancel()

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

protected

Callback function used to start the thread.

Referenced by threadTag().

## threadTag()

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

inline protected virtual

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

References main(), and testcancel().

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

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

- thread.h
- thread.cpp