v2.10-0 (21000JUN2005)

Go4ThreadManager
Class TGo4Thread


class TGo4Thread
derived from TNamed

Class that encapsulates a root TThread which calls a user runnable Method
(TGo4Runnable::Run()) in a loop. This working loop can be suspended to a
condition wait to stop the action.

Author:
J. Adamczewski, Go4 project-DVEE-GSI Darmstadt, Germany, j.adamczewski@gsi.de
Version: 0.9
Since: jul 2000-oct 2001

Field Summary
 private Bool_tfbIsCreated
          kTRUE if TThread instance exists and pthread is
created
 private Bool_tfbIsInternal
          specifes whether thread is internal thread of handlerr
(true) or is owned by external class (false).
 private Bool_tfbIsRunning
          Flag that controls Workfunc loop within Threadfunc
 private Bool_tfbIsWaiting
          true if Threadfunc is suspended to condition wait
 private Int_tfiThreadPID
          linux process id associated with the pthread
 private Int_tfiThreadSelfID
          self id of the current thread
 private TCondition*fxCondition
           
 private TGo4Runnable*fxRunnable
          External class providing the threaded workfunction
and exception routines for workfunction.
 private TThread*fxThread
           

Fields inherited from class TNamed
fName, fTitle

Constructor Summary
 TGo4Thread(const TGo4Thread& right)
           
 TGo4Thread(const char * name, TGo4Runnable* runnable, Bool_t internal)
          TGo4Thread constructor parameters:
name: name of the thread
runnable: external user runnable to be executed from TThread.
internal: define if thread shall be owned by threadmanager,
or if it belongs to other aggregation
 private TGo4Thread()
           

Destructor Summary
 virtual synchronized ~TGo4Thread()
           

Method Summary
 Bool_tCancel()
          Cancels TThread
 Bool_tCreate()
          creates the TThread if not yet existing
 private TCondition*GetCondition()
           
 const Int_tGetPID()
          linux process id associated with the pthread
 private TGo4Runnable*GetRunnable()
          We need this to have access to instance runnable from static Threadfunc:
 const Int_tGetSelfID()
          self id of the current thread
 const Bool_tIsCreated()
          kTRUE if TThread instance exists and pthread is
created
 const Bool_tIsInternal()
          returns flag indicating if go4thread object is internal
to threadhandler or created externally
 const Bool_tIsRunning()
          Flag that controls Workfunc loop within Threadfunc
 Bool_tIsWaiting()
          true if Threadfunc is suspended to condition wait
 synchronized TGo4Thread&operator=(const TGo4Thread& right)
           
 Bool_tReCreate()
          Stops old Runnable;
Creates new TThread of same Runnable and name;
cancels old Thread
 private voidSetPID()
           
 private voidSetSelfID()
           
 private voidSetWaiting(Bool_t mode)
           
 static voidSleep(UInt_t millisecs)
          wrapper for gSystem->Sleep with consecutive
TThread::CancelPoint - necessary for proper pthread
termination
 Bool_tStart()
          starts runnable method Run within thread loop
by setting running flag and signaling condition
 Bool_tStop()
          resets running flag for runnable
 private static voidThreadfunc(void * arg)
          This function is passed to TThread
ctor and runs as pthread.

Methods inherited from class TNamed
operator=, Clear, Clone, Compare, Copy, FillBuffer, GetName, GetTitle, Hash, IsSortable, SetName, SetNameTitle, SetTitle, ls, Print, Sizeof, Class, Class_Name, Class_Version, Dictionary, IsA, ShowMembers, Streamer, StreamerNVirtual, DeclFileName, ImplFileLine, ImplFileName, DeclFileLine

Field Detail

fbIsCreated

private Bool_t fbIsCreated
kTRUE if TThread instance exists and pthread is
created

fbIsInternal

private Bool_t fbIsInternal
specifes whether thread is internal thread of handlerr
(true) or is owned by external class (false). In the
latter case,
thread instance and its runnable are not deleted when
it is removed from the thread list

fbIsRunning

private Bool_t fbIsRunning
Flag that controls Workfunc loop within Threadfunc

fbIsWaiting

private Bool_t fbIsWaiting
true if Threadfunc is suspended to condition wait

fiThreadPID

private Int_t fiThreadPID
linux process id associated with the pthread

fiThreadSelfID

private Int_t fiThreadSelfID
self id of the current thread

fxCondition

private TCondition* fxCondition

fxRunnable

private TGo4Runnable* fxRunnable
External class providing the threaded workfunction
and exception routines for workfunction. The threaded
action will be defined by creating a runnable subclass
and overriding the TGo4Runnable::Run() method. Here exception
handling behaviour may be overridden, too.
supplierCardinality 1
clientCardinality 1

fxThread

private TThread* fxThread
Constructor Detail

TGo4Thread

public TGo4Thread(const TGo4Thread& right)

TGo4Thread

public TGo4Thread(const char * name, TGo4Runnable* runnable, Bool_t internal)
TGo4Thread constructor parameters:
name: name of the thread
runnable: external user runnable to be executed from TThread.
internal: define if thread shall be owned by threadmanager,
or if it belongs to other aggregation

TGo4Thread

private TGo4Thread()
Method Detail

~TGo4Thread

public virtual synchronized ~TGo4Thread()
Method Detail

Cancel

public Bool_t Cancel()
Cancels TThread

Create

public Bool_t Create()
creates the TThread if not yet existing

GetCondition

private TCondition* GetCondition()

GetPID

public const Int_t GetPID()
linux process id associated with the pthread

GetRunnable

private TGo4Runnable* GetRunnable()
We need this to have access to instance runnable from static Threadfunc:

GetSelfID

public const Int_t GetSelfID()
self id of the current thread

IsCreated

public const Bool_t IsCreated()
kTRUE if TThread instance exists and pthread is
created

IsInternal

public const Bool_t IsInternal()
returns flag indicating if go4thread object is internal
to threadhandler or created externally

IsRunning

public const Bool_t IsRunning()
Flag that controls Workfunc loop within Threadfunc

IsWaiting

public Bool_t IsWaiting()
true if Threadfunc is suspended to condition wait

operator=

public synchronized TGo4Thread& operator=(const TGo4Thread& right)

ReCreate

public Bool_t ReCreate()
Stops old Runnable;
Creates new TThread of same Runnable and name;
cancels old Thread

SetPID

private void SetPID()

SetSelfID

private void SetSelfID()

SetWaiting

private void SetWaiting(Bool_t mode)

Sleep

public static void Sleep(UInt_t millisecs)
wrapper for gSystem->Sleep with consecutive
TThread::CancelPoint - necessary for proper pthread
termination

Start

public Bool_t Start()
starts runnable method Run within thread loop
by setting running flag and signaling condition

Stop

public Bool_t Stop()
resets running flag for runnable

Threadfunc

private static void Threadfunc(void * arg)
This function is passed to TThread
ctor and runs as pthread.
Contains a loop that is controlled by
Go4Thread own TCondition and
by "function shall run" flag.
Within the loop the virtual
working function is called.

Association Links

to Class TGo4Runnable

External class providing the threaded workfunction
and exception routines for workfunction. The threaded
action will be defined by creating a runnable subclass
and overriding the TGo4Runnable::Run() method. Here exception
handling behaviour may be overridden, too.

Client Cardinality 1
Supplier Cardinality 1

to Class TThread

to Class TCondition


J.Adamczewski, M.Al-Turany, D.Bertini, H.G.Essel, S.Linev

30-06-2005