FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
CTCLThread Class Referenceabstract

#include <CTCLThread.h>

Public Member Functions

 CTCLThread (int flags=TCL_THREAD_JOINABLE, int stacksize=TCL_THREAD_STACK_DEFAULT)
 
virtual ~CTCLThread ()
 
void start (ClientData pData=nullptr)
 
void requestExit ()
 
virtual int operator() (ClientData arg)=0
 
virtual void exitHandler ()
 
int join ()
 

Static Public Member Functions

static Tcl_ThreadId currentThread ()
 

Protected Member Functions

bool exitRequested () const
 

Detailed Description

Concrete derivations of this class are instances of threads that are started using the TCL API (Tcl_CreateThread).

Constructor & Destructor Documentation

◆ CTCLThread()

CTCLThread::CTCLThread ( int  flags = TCL_THREAD_JOINABLE,
int  stacksize = TCL_THREAD_STACK_DEFAULT 
)

constructor We save the stack and flags for when start is called at which point they'll be needed.

Parameters
flags- start flags.
stacksize- bytes in stack.

◆ ~CTCLThread()

CTCLThread::~CTCLThread ( )
virtual

destructor This must be used with caution. Ideally the sequence is

  • Construct a thread.
  • Start the thread.
  • Ask the thread to exit (if it supports that).
  • join the thread (if it supports that).
  • Now that the thread is no longer schedulable destroy .

Member Function Documentation

◆ currentThread()

Tcl_ThreadId CTCLThread::currentThread ( )
static

currentThread [static] Returns the current thread id

Returns
Tcl_ThreadId

◆ exitHandler()

void CTCLThread::exitHandler ( )
virtual

exitHandler The runTrampoline, running in the context of the thread, always sets up an exit handler which, eventually invokes us. Since exit handlers are optional, we provide a default do-nothing handler. Tcl provides for a chain of handlers. This is less appropriate for an object oriented thread. We do recommend, however that at an appropriate time, overrides of this invoke the base class exit handler so we get object oriented exit handler chaning.

◆ exitRequested()

bool CTCLThread::exitRequested ( ) const
protected

exitRequested

Returns
bool - returns true if exit was requested.

◆ join()

int CTCLThread::join ( )

join If the thread is joinable and running it can be joined here. If this is not the case, an exception will be thrown

Returns
int - exit code of the thread.
Exceptions
std::logic_errorif join could not be done.

◆ requestExit()

void CTCLThread::requestExit ( )

requestExit There's no way to actually force the exit of a thread. What we can do is set a flag (m_exitRequested) and hope the thread looks at it from time to time (via exitRequested) and, when its true cleans up and exits. There is no penalty to ask for an exit more than once.

◆ start()

void CTCLThread::start ( ClientData  pData = nullptr)

start Starts the thread:

  • Any client data is putin the m_trampolineArgs struct as m_pArg.
  • Tcl_CreateThread is called with runTrampoline as the thread run function with a pointer to m_trampolnieArgs as the client data.
    Parameters
    pData- argument to pass to operator() - defaults to a nullptr.

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