INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

gbxiceutilacfr::Thread Class Reference

A minor extention of the IceUtil::Thread class. More...

#include <thread.h>

Inherits gbxutilacfr::Stoppable.

Inherited by gbxiceutilacfr::SafeThread, TestThread, TestThreadWithExit, TestThreadWithNap, TestThreadWithThrow, and TestThreadWithWait.

List of all members.

Public Member Functions

void stop ()
virtual bool isStopping ()
 Returns TRUE if the thread is in Stopping state, FALSE otherwise.
bool isStarted ()
 Returns TRUE if the thread is in Started state, FALSE otherwise.
bool isActive ()

Protected Member Functions

void waitForStop ()


Detailed Description

A minor extention of the IceUtil::Thread class.

Adds an option to stop a thread with stop(). Requires that the thread periodically checks whether it has to stop by calling isStopping(); Since stop() is public, it can be called from inside or outside of the derived class.

To use this class, simply overload the virtual IceUtil::Thread::run() function.

void MyThread::run()
{
    // initialize

    // main loop
    while ( !isStopping() )
    {
        // do something
    }

    // clean up
}

The implicit state machine of this class has 4 states {Starting, Running, Stopping, Stopped}. Events and the corresponding state transitions are listed below. Note that the final state may only be accessed when using smart pointer gbxiceutilacfr::ThreadPtr (otherwise the thread self-destructs).

EVENT      : Constructor IceUtil::Thread::Thread()
TRANSITION : Starting    
INTERNAL   : isStopping()=false, isAlive()=false, isStarted()=false

EVENT      : IceUtil::Thread::start()
TRANSITION : Starting -> Running     
INTERNAL   : isStopping()=false, isAlive()=true, isStarted()=true

EVENT      : gbxiceutilacfr::Thread::stop()
TRANSITION : Running -> Stopping    
INTERNAL   : isStopping()=true, isAlive()=true, isStarted()=true

EVENT      : termination of run() function.
TRANSITION : Stopping -> Stopped     
INTERNAL   : isStopping()=true, isAlive()=false, isStarted()=true

Caveats:

  • Make sure you catch all exception which can possibly be raised inside IceUtil::Thread::run. Otherwise, you'll see "uncaught exception" printed out and the component will hang.
  • gbxiceutilacfr::Threads self-destruct (ie call their own destructor) when gbxiceutilacfr::Thread::run returns, unless you hold onto an gbxiceutilacfr::ThreadPtr which points to it. So never call delete on the pointer to a thread, doing so will result in segmentation fault.

See also:
SafeThread

Member Function Documentation

bool gbxiceutilacfr::Thread::isActive (  )  [inline]

Depricated function! Use isStopping() instead (note that it returns the opposite).

Returns FALSE if thread was told to stop, TRUE otherwise.

References isStopping().

void gbxiceutilacfr::Thread::stop (  ) 

Lets the thread know that it's time to stop. Thread-safe, so it can be called from inside or outside this thread.

Referenced by gbxiceutilacfr::stop(), and gbxiceutilacfr::stopAndJoin().

void gbxiceutilacfr::Thread::waitForStop (  )  [protected]

Wait for someone from the outside to call stop. It may be necessary to call this function before exitting from IceUtil::Thread::run after catching an exception. If we just exit from run() and someone calls our stop() function afterwards there's a possibility of lock up.

References isStopping().

Referenced by gbxiceutilacfr::SafeThread::run().


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

Generated for GearBox by  doxygen 1.4.5