Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends

ACS::Thread Class Reference

#include <acsThread.h>

Inheritance diagram for ACS::Thread:
Inheritance graph
[legend]
Collaboration diagram for ACS::Thread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Thread (const ACE_CString &name, const TimeInterval &responseTime=ThreadBase::defaultResponseTime, const TimeInterval &sleepTime=ThreadBase::defaultSleepTime, const bool del=false, const long _thrFlags=THR_NEW_LWP|THR_DETACHED, const size_t stackSize=ACE_DEFAULT_THREAD_STACKSIZE)
virtual ~Thread ()
virtual void onStart ()
virtual void onStop ()
virtual void commonStart ()
virtual void commonStop ()
virtual void run ()
virtual void runLoop ()

Protected Member Functions

ACS::ThreadManagergetThreadManager () const

Static Protected Member Functions

static void threadSvc (void *param)

Protected Attributes

LoggingProxylogger_mp
 ponter to Logging proxy
ACS::ThreadManagerthrMgr_mp
 Pointer to thread manager.

Private Member Functions

void operator= (const Thread &)
 Thread (const Thread &)

Private Attributes

bool delete_m

Friends

class ThreadManager

Detailed Description

Thread class is a base class for the ACS based threads. If a user wants to define his/her own thread, it has to create a class which derives from ACS::hread class and the override run or runLoop methods.

The Thread class is ment to be used with the support of a ThreaManager.

It is possible to use it without a ThreadManager, but you have to be careful and read accurately this documentation to be aware of things you have to be careful with.


Constructor & Destructor Documentation

ACS::Thread::Thread ( const ACE_CString &  name,
const TimeInterval &  responseTime = ThreadBase::defaultResponseTime,
const TimeInterval &  sleepTime = ThreadBase::defaultSleepTime,
const bool  del = false,
const long  _thrFlags = THR_NEW_LWP|THR_DETACHED,
const size_t  stackSize = ACE_DEFAULT_THREAD_STACKSIZE 
)

Constructor of the Thread class. If someone wants to set thread parameters, s/he has to send these parameters from the constructor of the derived class up to the base class.

Exceptions:
acsthreadErrType::CanNotSpawnThreadExImpl 
Parameters:
name thread's name
responsTime thread's heartbeat response time in 100ns unit. Default value is 1s.
sleepTime thread's sleep time in 100ns unit Default value is 100ms.
del should the thread object be deleted automatically after the thread exits.
Default is not (=false).
If the thread object has to be deleted after the thread exits (i.e. del=true), a detached instead of a joinable thread is created.
Attention:
This means that the thread will call 'delete this' after the thread function execution is completed.
This can work only for threads allocated on the heap and the user has to be careful not to use the pointer after thread execution is started, because the object could be deleted at any time.
A ThreadManager always creates a thread with new (on a heap) !!! It is not possible to call restart() on auto delete threads, because the thread object would be deleted when the thread is stopped.
all of thread will be suspended.
This has been done to protect the code from creation concurrency problems.
If we would start execution of the thread service function in the constructor of the Thread class, the user thread function would be potentially executed BEFORE the object is fully constructed and data members and virtual tables are allocated and initialised. Therefore we have decided to always suspend the thread. The developer of a subclass can use the parameter to resume() the thread at the end of its own constructor, when everything has been allocated and initialised or can choose to do it afterwards.
The ThreadManager does exactly this:
  • creates the Thread object suspended
  • if was to be not-suspended calls release() after construction
autodelete threads are created as non joinable, but all other threads are created joinable and the developer has to take care of joining them, otherwise resourses will be lost and it will be possible to allocate only a few hundred tests before crashing the machine

2006/07/06 merge two constructor, since there is almost no difference between them

Parameters:
_stackSize The size of the stack of the thread. If ACE_DEFAULT_THREAD_STACKSIZE the default ACE stack size is taken.
virtual ACS::Thread::~Thread (  )  [virtual]

Thread destructor.

ACS::Thread::Thread ( const Thread  )  [private]

ALMA C++ coding standards state copy constructors should be disabled.


Member Function Documentation

virtual void ACS::Thread::commonStart (  )  [virtual]

This method performs basic thread initialization, common to all threads. It is called by threadSvc and call the user hook onStart. The common initialization performs the initialization of the logging system, which has to be done on a per thread base. It shall not be overridden unless it is really necessary (for example. user does not like what is done for common initialization). In most cases if should be sufficient to override of onStart.

virtual void ACS::Thread::commonStop (  )  [virtual]

This method performs basic thread cleanup, common to all threads. It is called by threadSvc and call the user hook onStop. The common cleanup performs the cleanup of the logging system, which has to be done on a per thread base. It shall not be overridden unless it is really necessary (for example. user does not like what is done for common cleanup). In most cases if should be sufficient to override of onStop.

ACS::ThreadManager* ACS::Thread::getThreadManager (  )  const [protected]

Returns pointer to the thread manager responsible for this thread.

virtual void ACS::Thread::onStart (  )  [inline, virtual]

Method which is executed before the body of the thread. It is the hook method for a user that wants to do some initialization before the thread execution (thread initialization), s/he has to override/implement this method in the implementation class. It is called by commonStart

Reimplemented in RequestProcessorThread, ControllerThread, and DoorThread.

virtual void ACS::Thread::onStop (  )  [inline, virtual]

Method which is executed after the body of the thread, i.e. after the thread execution. It is the hook method for a user that wants to do some cleanup after the thread execution (thread cleanup), s/he has to override/implement this method in the implementation class. It is called by commonStop

Reimplemented in DoorThread.

void ACS::Thread::operator= ( const Thread  )  [private]

ALMA C++ coding standards state assignment operators should be disabled.

virtual void ACS::Thread::run (  )  [virtual]

Basic used hook to implement the thread functionality. The provided default implementation executes the method runLoop in a loop, to provide periodic loops. If a user wants that his/her thread function is executed periodically, s/he has to override the runLoop. Between two iterations the runLoop sleeps for responseTime 100ns If a user wants that his/her thread function is executed only once, s/he has to override this method.

Reimplemented in SenderThread.

virtual void ACS::Thread::runLoop (  )  [inline, virtual]

Basic used hook to implement the thread functionality in a periodic loop. The method is executed in a loop until the thread is alive and every responseTime 100ns by the run method. The thread can be exited from the lop by calling ACS::ThreadBase::stop or ACS::ThreadBase::exit command. If the run method is overridden than runLoop is not executed.

Reimplemented in acsalarm::AlarmsMap, acsalarm::AlarmSourceImpl, PositionControlThread, PositionControlThread, RequestProcessorThread, ControllerThread, DoorThread, FridgeThread, SamplingThread< ACS_SAMP_C >, SamplingThreadFlush< ACS_SAMP_C >, TestACSThread, SamplingThread< ACS_SAMP_TL >, and SamplingThreadFlush< ACS_SAMP_TL >.

static void ACS::Thread::threadSvc ( void *  param  )  [static, protected]

Static method which is passed to the ACE thread manager which than spawns the thread. This is the actual thread service function. It executes:


Friends And Related Function Documentation

friend class ThreadManager [friend]

Member Data Documentation

bool ACS::Thread::delete_m [private]

flag that indicates if thread should be deleted after the thread exits

ponter to Logging proxy

Pointer to thread manager.


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