artefaktur
software engineer &        architecture

 
 
 
 

class Thread

Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members   Related Pages  

acdk::lang::Thread Class Reference

#include <Thread.h>

Inheritance diagram for acdk::lang::Thread:

acdk::lang::Object acdk::lang::Runnable acdk::lang::ObjectBase acdk::lang::dmi::StdDispatch acdk::make::PooledThread acdk::make::ThreadPool acdk::net::srfsys::SRFileSystemServer acdk::tools::aunit::guitestrunner::TestRunThread acdk::util::PropertiesListener acdkx::orb::AORB acdkx::rdmi::RemoteDmiServer acdkx::rdmi::ThreadedConnectionHandler tests::acdk::lang::dmi::NotifyObjectEventThread tests::acdk::lang::dmi::UseReferenceThread tests::acdk::lang::DoNothingRunnable tests::acdk::lang::FloadThread tests::acdk::lang::PollOnThreadLocal tests::acdk::lang::ProcessOutReaderThread tests::acdk::lang::sys::MyThread tests::acdk::lang::ThrowNullPointerThread tests::acdk::lang::ThrowUnhandledNullPointerThread tests::acdk::net::EchoThread tests::acdk::net::UDPServer tests::acdkx::orb::BasicTestClient tests::acdkx::orb::TestAcdkImplServer tests::acdkx::orb::TestInterfaceImplServer List of all members.

Detailed Description

This is base implementation to start and manage Thread.

Use not the default constructor Thread(). If you use thread functionality of ACDK it is important to use the System::main funktionality for proper initialization.

See also acdk::lang::Runnable here in Package acdk::lang.

Author:
Roger Rene Kommer
Version:
Revision
1.28
Date:
Date
2005/04/22 11:13:56


Public Types

enum  State {
  Created, Running, Suspended, Terminated,
  Detached
}

Public Member Functions

 Thread (IN(RRunnable) target=Nil, IN(RString) name=Nil)
 Construct an user Thread.

 Thread (IN(RThreadGroup) group, IN(RRunnable) target=Nil, IN(RString) name=Nil)
 Construct an user Thread.

 Thread (ThreadType type, IN(RString) name=Nil)
 Construct an system or main Thread.

virtual ~Thread ()
virtual RString toString ()
 reimplemented from String

virtual void join (int millis=-1, int nanos=0) throw ( RIllegalArgumentException )
virtual void interrupt ()
 Interrupt this thread.

virtual bool isInterrupted ()
 return true if this thread has interrupted signal set

bool isAlive ()
 return true if thread is running

virtual void start ()
 start the thread

virtual void run ()
 overload this method to implement working code for this thread

virtual int getPriority ()
 return the priority of this thread

virtual void setPriority (int newPriority)
 sets the priority of this thread 0 (hight) - 5 (low)

RThreadGroup getThreadGroup ()
 return the threadgroup associated with this thread

int getActiveCount ()
 non static version of activeCount()

virtual int countStackFrames ()
 return stack frames in this thread.

virtual void destroy ()
 Kills this thread, without releasing any resource.

virtual void stop ()
 calls stop(new ThreadDeath())

virtual void stop (IN(RThrowable) exception)
 The given exception will be thrown in the thread either it is in a waiting situation (inside wait, sleep, join, etc.) or the thread is calling the Thread::checkForPendingException().

virtual void suspend ()
 Suspends the thread.

virtual void resume ()
 weak up thread previously suspended with suspend()

virtual void setDaemon (bool on)
 set this thread to a deamon thread

virtual bool isDaemon ()
virtual void setName (RString str)
void doSleep (int millis)
 internal helper

void _saveStackBase (unsigned int sp)
 System should be friend of it, but include-chain disallows it.

void setThreadExceptionToThrow (IN(RThrowable) ex)
 after basic operations (like sleep) it calls checkForThreadException() and if a throwable was set with setThreadExceptionToThrow this exception will be raised

RThrowable getThreadExceptionToThrow ()
void checkForThreadException ()
 throws a previously set exception
Exceptions:
IllegalThreadStateException if called outside this thread


bool _readResetIsInterrupted ()
 internal helper

void setCurrentWaitingMonitor (MonitorInterface *monitor)
Thread::State _getState () const
void _setState (Thread::State state)
ThreadID threadID ()
const ThreadID threadID () const
HANDLE threadHandle ()
bool _isThisThreadCurrent ()

Static Public Member Functions

bool interrupted ()
 return true if currentThread() is interrupted

void yield ()
 force switch to another thread

void sleep (int millis, int nanaos=0)
 Sleep the current threads.

RThread currentThread ()
 return the current thread

int activeCount ()
 delegate to ThreadGroup::activeCount if exists otherwise return 1

unsigned int getStackBase ()
int enumerate (IN(RThreadArray) tarray)
 List all threads of current threadgroup.

void dumpStack ()
 calls acdk::lang::System::printStackTrace()

int getThreadCount ()
 return the known threads, whereas main thread not included

void newSystemThread (ThreadType type=SystemThreadType)
 a new system thread was dedected

void removeSystemThread ()
 remove this system thread

void checkSystemThreads ()
 checks if all thread are registered, removes zombies

bool isSingleThreaded ()
void checkForPendingException ()
 calls currentThread()->checkForThreadException()

void setCurrentMonitor (MonitorInterface *monitor)
 set current waiting monitor

unsigned int _stdcall _Win32ThreadFunc (void *arg)
ThreadID currentThreadId ()

Public Attributes

HANDLE _threadHandle

Protected Member Functions

void _invokeThreadException ()
void _run ()
void _checkAccess ()

Protected Attributes

ThreadID _threadID

Private Types

typedef sys::core_fastmutex InternalMutexType
 for protecting setting/reading internal state


Static Private Member Functions

void * _posixThreadFunc (void *arg)

Private Attributes

RRunnable _runnable
RString _name
Thread::State _state
bool _isDaemon
bool _interrupted
 thread should be interrupted

MonitorInterface * _currentMonitor
 this lock is currently waiting

ThreadType _type
RThreadGroup _group
RThrowable _exceptionToThrow
InternalMutexType _internalMutex
RObject _startSync
 used to wait in start until Thread finisished initializing


Static Private Attributes

sys::core_atomicop _threadCount

Member Typedef Documentation

typedef sys::core_fastmutex acdk::lang::Thread::InternalMutexType [private]
 

for protecting setting/reading internal state


Member Enumeration Documentation

enum acdk::lang::Thread::State
 

Enumeration values:
Created 
Running 
Suspended 
Terminated 
Detached 

Constructor & Destructor Documentation

acdk::lang::Thread::Thread IN(RRunnable target = Nil,
IN(RString name = Nil
 

Construct an user Thread.

acdk::lang::Thread::Thread IN(RThreadGroup group,
IN(RRunnable target = Nil,
IN(RString name = Nil
 

Construct an user Thread.

acdk::lang::Thread::Thread ThreadType  type,
IN(RString name = Nil
 

Construct an system or main Thread.

virtual acdk::lang::Thread::~Thread  )  [virtual]
 


Member Function Documentation

void acdk::lang::Thread::_checkAccess  )  [protected]
 

Thread::State acdk::lang::Thread::_getState  )  const [inline]
 

void acdk::lang::Thread::_invokeThreadException  )  [protected]
 

bool acdk::lang::Thread::_isThisThreadCurrent  )  [inline]
 

void* acdk::lang::Thread::_posixThreadFunc void *  arg  )  [static, private]
 

bool acdk::lang::Thread::_readResetIsInterrupted  ) 
 

internal helper

void acdk::lang::Thread::_run  )  [protected]
 

void acdk::lang::Thread::_saveStackBase unsigned int  sp  )  [inline]
 

System should be friend of it, but include-chain disallows it.

void acdk::lang::Thread::_setState Thread::State  state  )  [inline]
 

unsigned int _stdcall acdk::lang::Thread::_Win32ThreadFunc void *  arg  )  [static]
 

int acdk::lang::Thread::activeCount  )  [static]
 

delegate to ThreadGroup::activeCount if exists otherwise return 1

void acdk::lang::Thread::checkForPendingException  )  [inline, static]
 

calls currentThread()->checkForThreadException()

void acdk::lang::Thread::checkForThreadException  )  [inline]
 

throws a previously set exception

Exceptions:
IllegalThreadStateException if called outside this thread

void acdk::lang::Thread::checkSystemThreads  )  [static]
 

checks if all thread are registered, removes zombies

virtual int acdk::lang::Thread::countStackFrames  )  [virtual]
 

return stack frames in this thread.

This method only works with currentThread.

RThread acdk::lang::Thread::currentThread  )  [static]
 

return the current thread

ThreadID acdk::lang::Thread::currentThreadId  )  [static]
 

virtual void acdk::lang::Thread::destroy  )  [virtual]
 

Kills this thread, without releasing any resource.

Reimplemented in acdkx::orb::AORB.

void acdk::lang::Thread::doSleep int  millis  ) 
 

internal helper

void acdk::lang::Thread::dumpStack  )  [static]
 

calls acdk::lang::System::printStackTrace()

int acdk::lang::Thread::enumerate IN(RThreadArray tarray  )  [static]
 

List all threads of current threadgroup.

int acdk::lang::Thread::getActiveCount  ) 
 

non static version of activeCount()

virtual int acdk::lang::Thread::getPriority  )  [virtual]
 

return the priority of this thread

unsigned int acdk::lang::Thread::getStackBase  )  [inline, static]
 

Deprecated:
should not be used

int acdk::lang::Thread::getThreadCount  )  [inline, static]
 

return the known threads, whereas main thread not included

RThrowable acdk::lang::Thread::getThreadExceptionToThrow  )  [inline]
 

RThreadGroup acdk::lang::Thread::getThreadGroup  ) 
 

return the threadgroup associated with this thread

virtual void acdk::lang::Thread::interrupt  )  [virtual]
 

Interrupt this thread.

bool acdk::lang::Thread::interrupted  )  [static]
 

return true if currentThread() is interrupted

bool acdk::lang::Thread::isAlive  ) 
 

return true if thread is running

virtual bool acdk::lang::Thread::isDaemon  )  [inline, virtual]
 

virtual bool acdk::lang::Thread::isInterrupted  )  [virtual]
 

return true if this thread has interrupted signal set

bool acdk::lang::Thread::isSingleThreaded  )  [inline, static]
 

virtual void acdk::lang::Thread::join int  millis = -1,
int  nanos = 0
throw ( RIllegalArgumentException ) [virtual]
 

void acdk::lang::Thread::newSystemThread ThreadType  type = SystemThreadType  )  [static]
 

a new system thread was dedected

void acdk::lang::Thread::removeSystemThread  )  [static]
 

remove this system thread

virtual void acdk::lang::Thread::resume  )  [virtual]
 

weak up thread previously suspended with suspend()

virtual void acdk::lang::Thread::run  )  [virtual]
 

overload this method to implement working code for this thread

Implements acdk::lang::Runnable.

Reimplemented in acdk::make::ThreadPool, acdk::make::PooledThread, acdk::net::srfsys::SRFileSystemServer, acdk::tools::aunit::guitestrunner::TestRunThread, acdk::util::PropertiesListener, acdkx::orb::AORB, acdkx::rdmi::RemoteDmiServer, acdkx::rdmi::ThreadedConnectionHandler, tests::acdk::lang::FloadThread, tests::acdk::lang::ProcessOutReaderThread, tests::acdk::lang::DoNothingRunnable, tests::acdk::lang::PollOnThreadLocal, tests::acdk::lang::ThrowNullPointerThread, tests::acdk::lang::ThrowUnhandledNullPointerThread, tests::acdk::lang::dmi::NotifyObjectEventThread, tests::acdk::lang::dmi::UseReferenceThread, tests::acdk::lang::sys::MyThread, tests::acdk::net::UDPServer, tests::acdk::net::EchoThread, tests::acdkx::orb::BasicTestClient, tests::acdkx::orb::TestInterfaceImplServer, and tests::acdkx::orb::TestAcdkImplServer.

void acdk::lang::Thread::setCurrentMonitor MonitorInterface *  monitor  )  [inline, static]
 

set current waiting monitor

void acdk::lang::Thread::setCurrentWaitingMonitor MonitorInterface *  monitor  )  [inline]
 

virtual void acdk::lang::Thread::setDaemon bool  on  )  [inline, virtual]
 

set this thread to a deamon thread

virtual void acdk::lang::Thread::setName RString  str  )  [virtual]
 

virtual void acdk::lang::Thread::setPriority int  newPriority  )  [virtual]
 

sets the priority of this thread 0 (hight) - 5 (low)

void acdk::lang::Thread::setThreadExceptionToThrow IN(RThrowable ex  )  [inline]
 

after basic operations (like sleep) it calls checkForThreadException() and if a throwable was set with setThreadExceptionToThrow this exception will be raised

void acdk::lang::Thread::sleep int  millis,
int  nanaos = 0
[static]
 

Sleep the current threads.

Parameters:
millis milli seconds
nanaos nano seconds

virtual void acdk::lang::Thread::start  )  [virtual]
 

start the thread

Reimplemented in acdkx::orb::AORB.

virtual void acdk::lang::Thread::stop IN(RThrowable exception  )  [virtual]
 

The given exception will be thrown in the thread either it is in a waiting situation (inside wait, sleep, join, etc.) or the thread is calling the Thread::checkForPendingException().

If the given exception is not of type ThreadDeath or InterruptedException the stop() method will try to load the extended metainfo for this exception type to throw the instance.

virtual void acdk::lang::Thread::stop  )  [virtual]
 

calls stop(new ThreadDeath())

See also:
void stop(IN(RThrowable) obj);

virtual void acdk::lang::Thread::suspend  )  [virtual]
 

Suspends the thread.

If calling inside this thread the thread stops until the thread will be resumed outside this thread. Calling suspend() may result in a deadlock situtation if the thread currently holds a lock on thread-shared ressources

HANDLE acdk::lang::Thread::threadHandle  )  [inline]
 

const ThreadID acdk::lang::Thread::threadID  )  const [inline]
 

ThreadID acdk::lang::Thread::threadID  )  [inline]
 

virtual RString acdk::lang::Thread::toString  )  [virtual]
 

reimplemented from String

Reimplemented from acdk::lang::Object.

Reimplemented in tests::acdk::lang::ProcessOutReaderThread.

void acdk::lang::Thread::yield  )  [static]
 

force switch to another thread


Member Data Documentation

MonitorInterface* acdk::lang::Thread::_currentMonitor [private]
 

this lock is currently waiting

RThrowable acdk::lang::Thread::_exceptionToThrow [private]
 

RThreadGroup acdk::lang::Thread::_group [private]
 

InternalMutexType acdk::lang::Thread::_internalMutex [private]
 

bool acdk::lang::Thread::_interrupted [private]
 

thread should be interrupted

bool acdk::lang::Thread::_isDaemon [private]
 

RString acdk::lang::Thread::_name [private]
 

RRunnable acdk::lang::Thread::_runnable [private]
 

RObject acdk::lang::Thread::_startSync [private]
 

used to wait in start until Thread finisished initializing

Thread::State acdk::lang::Thread::_state [private]
 

sys::core_atomicop acdk::lang::Thread::_threadCount [static, private]
 

HANDLE acdk::lang::Thread::_threadHandle
 

ThreadID acdk::lang::Thread::_threadID [protected]
 

ThreadType acdk::lang::Thread::_type [private]
 

 
Last modified 2005-05-08 18:32 by SYSTEM By Artefaktur, Ing. Bureau Kommer