Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
Thread Class ReferenceProvides a nice wrapping of pthreads library. More...
Inheritance diagram for Thread:
Detailed DescriptionProvides a nice wrapping of pthreads library. If you need to provide cleanup functions on stop(), cancelled(), etc., you should override the destructor to stop and join so that you can be assured that your cleanup will be called if the thread is auto-destructed by going out of scope Definition at line 38 of file Thread.h.
Constructor & Destructor Documentation
destructor, will stop and join the thread, but you should override it to do the same if you provide any cleanup functions Note that this destructor will send a stop() signal... if you want your subclass to let the thread run to its "natural" completion on destruction, you can either pushNoCancel() within the thread, or override the destructor to join() without stop()
don't call, not a well defined operation Member Function Documentation
called when handle_exit() is triggered, either by the thread being cancelled, or when run() has returned voluntarily Reimplemented in MessageQueueStatusThread. Definition at line 216 of file Thread.h. Referenced by handle_exit(), and warnSelfUndestructed().
called as last instruction of handle_exit(), following cancelled() and all other cleanup. A self-deleting thread should do so here. Definition at line 218 of file Thread.h. Referenced by handle_exit(), and stop().
returns the Thread object for the current thread (or NULL for the main thread) Definition at line 238 of file Thread.cc. Referenced by handle_exit(), handleInterrupt(), popNoCancel(), pushNoCancel(), requestInterruptOnCancel(), testCurrentCancel(), Thread(), unrequestInterruptOnCancel(), warnSelfUndestructed(), and ~Thread().
returns returnValue, for use with threads which may have intermediate results, or partial results following a cancellation
indicates the thread is exiting, either voluntary (run() returned), stop(), or kill() -- calls cancelled() for the thread as indicated by th Definition at line 370 of file Thread.cc. Referenced by handle_launch_signal(), and launch().
called by SIGALRM signal handler installed by interrupt() just before it posts the corresponding SIGALRM tests for thread cancel condition before calling on to interrupted() Reimplemented in PollThread. Definition at line 481 of file Thread.cc. Referenced by interrupt().
sends a signal (SIGALRM) to the thread which will interrupt any sleep/read/etc. calls (and trigger interrupted() to be called within the thread) This may be called to request a cancellation on systems which don't directly support pthread_cancel they way we would like. See stop(). Definition at line 135 of file Thread.cc. Referenced by CallbackPollThread::resetPeriod(), and stop().
called by handleInterrupt() in target thread following call to interrupt(), assuming thread has not been cancelled (which can intercept the interrupt) Reimplemented in PollThread. Definition at line 232 of file Thread.h. Referenced by handleInterrupt().
indicates whether the thread is currently alive and running, implies isStarted() Definition at line 168 of file Thread.h. Referenced by interrupt(), CallbackPollThread::resetPeriod(), and sendSignal().
indicates whether start() has been called (but may be some delay before isRunning() is true...) Definition at line 165 of file Thread.h. Referenced by MessageQueueStatusThread::addStatusListener(), MessageReceiver::finish(), MessageQueueStatusThread::removeStatusListener(), FailsafeThread::runloop(), MessageQueueStatusThread::~MessageQueueStatusThread(), MessageReceiver::~MessageReceiver(), and PollThread::~PollThread().
blocks calling thread until this Thread has terminated, either via run() returning of its own accord, or a stop() cancelling the thread return value is the response from run(), or CANCELLED if stop() was called. See getReturnValue() as a possible way to get results from a cancelled thread. Definition at line 221 of file Thread.cc. Referenced by MessageReceiver::finish(), ThreadedMessageQueue< EventBase * >::finishCallback(), ThreadedMessageQueue< EventBase * >::finishQueue(), FailsafeThread::runloop(), ThreadedMessageQueue< EventBase * >::stopCallback(), MessageReceiver::~MessageReceiver(), PollThread::~PollThread(), and ~Thread().
sends a SIGUSR1 to the thread, breaking its execution, but still allowing handle_exit (and thus cancelled()) to be called. Beware if your thread uses mutual exclusion locks, this can cause the thread to terminate while still holding locks Returns *this, for convenience of chaining a call to join()
thread entry point -- calls launched() on the thread (as indicated by msg), and then run() Definition at line 297 of file Thread.cc. Referenced by start().
called by launch() when thread is first entered, return false to cancel launch (set returnValue as well if you care) Reimplemented in MessageQueueStatusThread, and MessageReceiver. Definition at line 207 of file Thread.h. Referenced by launch().
detaches thread and sends SIGSTOP, which immediately halts the thread without any chance for cleanup Beware if your thread uses mutual exclusion locks, this will cause the thread to terminate while still holding locks. Returns *this, for convenience of chaining a call to join()
should be called whenever a critical section is left (i.e. mutex released) -- if it was the last one, tests cancellability as well if doTestCancel (generally should, except in destructors, may already be unwinding from exception, would cause terminate) Definition at line 420 of file Thread.cc. Referenced by MessageReceiver::runloop(), Thread::Lock::trylock(), Thread::Lock::unlock(), unrequestInterruptOnCancel(), and Thread::NoCancelScope::~NoCancelScope().
should be called whenever a critical section has been entered (i.e. mutex obtained) -- prevents cancel from occurring until popNoCancel() is called Definition at line 400 of file Thread.cc. Referenced by Thread::Lock::lock(), Thread::NoCancelScope::NoCancelScope(), requestInterruptOnCancel(), MessageReceiver::runloop(), and Thread::Lock::trylock().
Should be called before system calls which are not cancellation points, but support interruption by signal. On OS X, everything is done this way, so no need to call this function. Only needed for calls on systems where we actually use pthread_cancel (Linux), but at system calls which are not cancellation points. At the moment, semop() is the only known case. Definition at line 447 of file Thread.cc. Referenced by SemaphoreManager::add_testZero(), SemaphoreManager::add_testZero_add(), SemaphoreManager::lower(), SemaphoreManager::testZero(), and SemaphoreManager::testZero_add().
called by launch() once the thread has been set up; when this returns, the thread ends, see runloop() Default implementation repeatedly calls runloop(), usleep(), and testCancel(). If you override, you should also be sure to call testCancel occasionally in order to support stop() If function returns a value, that value overrides returnValue. If cancel occurs, returnValue is used. Reimplemented in CallbackThread, MessageQueueStatusThread, PollThread, and ThreadedMessageQueue< T >::ReceiverThread< F, C >. Definition at line 122 of file Thread.cc. Referenced by launch().
override this as a convenient way to define your thread -- return the number of *micro*seconds to sleep before the next call; return -1U to indicate end of processing Reimplemented in FailsafeThread, and MessageReceiver. Definition at line 214 of file Thread.h. Referenced by PollThread::poll(), and run().
sends a signal to the thread Definition at line 207 of file Thread.cc. Referenced by interrupt(), kill(), and murder().
requests that the thread be started, if not already running (you need to create separate instances if you want to run multiple copies) Reimplemented in PollThread. Definition at line 84 of file Thread.cc. Referenced by MessageQueueStatusThread::addStatusListener(), CallbackThread::CallbackThread(), FailsafeThread::FailsafeThread(), MessageReceiver::MessageReceiver(), FailsafeThread::runloop(), MessageQueueStatusThread::setMessageQueue(), ThreadedMessageQueue< EventBase * >::spawnCallback(), and CallbackThread::~CallbackThread().
requests that the thread be stopped gracefully, if running. A cancel flag is sent, and the thread will be stopped at next cancel point, defined by whenever testCancel(), or a set of other system functions, are called. See your system's pthread_testcancel() manual page for a list of cancel points. This function may imply a call to interrupt() on systems which have extremely limited system cancel points or don't handle thread cancellation as a C++ exception (currently this consists of Mac OS X and possibly other BSD-based systems). This means that you should be able to rely on using try/catch(...) to handle both exceptions as well as thread cancellation, but interruptable system calls should test errno for EINTR and call testCancel() when it is encountered to ensure portability. Returns *this, for convenience of chaining a call to join()
Reimplemented in MessageQueueStatusThread, and MessageReceiver. Definition at line 149 of file Thread.cc. Referenced by ThreadedMessageQueue< EventBase * >::finishCallback(), ThreadedMessageQueue< EventBase * >::finishQueue(), ThreadedMessageQueue< EventBase * >::stopCallback(), PollThread::~PollThread(), and ~Thread().
checks to see if stop() has been called for the currently executing thread, and if so, will exit (passing through handle_exit() first) Definition at line 221 of file Thread.h. Referenced by handleInterrupt(), launch(), popNoCancel(), run(), PollThread::run(), MessageQueueStatusThread::run(), FailsafeThread::runloop(), and unrequestInterruptOnCancel().
checks to see if stop() has been called for the current thread, and if so, will exit (passing through handle_exit() first) Definition at line 266 of file Thread.cc. Referenced by testCancel(), Thread::Condition::timedwait(), and Thread::Condition::wait().
Should be called after system calls which are not cancellation points, but support interruption by signal. On OS X, everything is done this way, so no need to call this function. Only needed for calls on systems where we actually use pthread_cancel (Linux), but at system calls which are not cancellation points. At the moment, semop() is the only known case. Definition at line 461 of file Thread.cc. Referenced by SemaphoreManager::add_testZero(), SemaphoreManager::add_testZero_add(), SemaphoreManager::lower(), SemaphoreManager::testZero(), and SemaphoreManager::testZero_add().
emit a warning that the last thread exited while the self-pointer thread-specific key still exists (need to call releaseMainThread() or handle_exit()) Definition at line 498 of file Thread.cc. Referenced by initMainThread(). Member Data Documentation
set to true if the cancellation has been triggered and stack unwind is in progress (don't throw anything!) Definition at line 262 of file Thread.h. Referenced by launch(), and testCurrentCancel().
cancel status at root of no-cancel stack (may be no-cancel through and through) Definition at line 258 of file Thread.h. Referenced by launch(), popNoCancel(), and pushNoCancel().
set to true once handle_exit() or murder() has been called, set back to false by start() (and initially by constructor) Definition at line 248 of file Thread.h. Referenced by handle_exit(), murder(), start(), and stop().
indicates a common group of threads, inherited from the thread which created this one, default NULL if created from main thread Definition at line 265 of file Thread.h. Referenced by getGroup(), setGroup(), and Thread().
depth of the pushNoCancel() stack Definition at line 252 of file Thread.h. Referenced by handle_exit(), handleInterrupt(), launch(), popNoCancel(), pushNoCancel(), stop(), testCurrentCancel(), unrequestInterruptOnCancel(), and warnSelfUndestructed().
depth of the requestInterruptOnCancel() stack Definition at line 255 of file Thread.h. Referenced by requestInterruptOnCancel(), stop(), and unrequestInterruptOnCancel().
indicates the value to be returned by the thread entry point (and thus passed back to join()) -- set this in runloop() or launched(), overridden by run()'s return value Definition at line 250 of file Thread.h. Referenced by getReturnValue(), join(), launch(), run(), and PollThread::run().
set to true once launch() has been called, set back to false by handle_exit(), or by murder() itself Definition at line 246 of file Thread.h. Referenced by handle_exit(), isRunning(), launch(), murder(), sendSignal(), MessageQueueStatusThread::setMessageQueue(), stop(), and warnSelfUndestructed().
set to true once start() has been called, set back to false by handle_exit(), or by murder() itself Definition at line 244 of file Thread.h. Referenced by handle_exit(), isStarted(), join(), murder(), sendSignal(), start(), stop(), warnSelfUndestructed(), and ~Thread().
prevents concurrent stops Definition at line 272 of file Thread.h. Referenced by handle_exit(), and stop(). The documentation for this class was generated from the following files: |
Tekkotsu v5.1CVS |
Generated Mon May 9 04:59:17 2016 by Doxygen 1.6.3 |