Sourceforge.net - The VCF's Project Host
   The VCF Website Home   |   Online Discussion Forums   |   Sourceforge.net Project Page   

VCF::Thread Class Reference

The Thread class represents a thread of execution in a process. More...

#include <vcf/FoundationKit/Thread.h>

Inheritance diagram for VCF::Thread:

VCF::Object VCF::Runnable VCF::Waitable VCF::PoolThread List of all members.

Public Member Functions

 Thread ()
 Thread (const bool &autoDelete)
 Thread (Runnable *runnableObject, const bool &autoDelete)
 creates a thread with the attached runnableObject (if appropriate)
 Thread (Runnable *runnableObject, const bool &autoDeleteRunnable, const bool &autoDelete)
 Creates a thread with a runnable object, and allows the thread to automatically delete the runnable if appropriate.
 Thread (Runnable *runnableObject)
virtual ~Thread ()
virtual bool run ()
 run method for the thread.
virtual void stop ()
 gracefully stops the thread and shuts it down, releasing any OS resources associated with the thread.
bool start ()
 Starts (or resumes) a thread running.
void sleep (uint32 milliseconds)
 causes the thread the thread to sleep for the specified number of milliseconds
bool canContinue ()
 can the thread continue to execute ?
bool canAutoDelete ()
 can the thread auto delete itself ?
uint32 getThreadID ()
 returns the thread associated with this thread of execution
uint32 getOwningProcessID ()
 returns the process ID that this thread is part of
ThreadPeergetPeer ()
bool isActive ()
 Returns TRUE if thread is running, FALSE if not.
virtual WaitResult wait ()
virtual Waitable::WaitResult wait (uint32 milliseconds)
virtual OSHandleID getPeerHandleID ()
RunLoopPtr::Shared getRunLoop ()
bool getRunsWithExceptionHandler ()
 Returns whether or not the thread's run() method is wrapped with an try/catch block.
void setRunsWithExceptionHandler (bool val)
 Sets the variable that determines whether or not the thread's run() method is wrapped in an try/catch block.
bool internal_isStopped ()
 for thread peer's usage only - called to see if the thread is being shutdown via the stop() method.
void internal_initBeforeRun ()
 Called by the thread peer implementation.
bool internal_run ()

Static Public Member Functions

static ThreadgetMainThread ()
 Returns the main or primary thread for a program.

Protected Attributes

bool canContinue_
RunnablerunnableObject_
ThreadPeerpeer_
bool autoDelete_
bool autoDeleteRunnable_
bool stopped_
RunLoopPtr::Shared runLoop_
bool runWithExceptionBlock_

Static Protected Attributes

static ThreadmainThread

Detailed Description

The Thread class represents a thread of execution in a process.

A Thread object can automatically delete itself if neccessary. A Thread can either be derived from and the run() method overridden, or a separate class that derives from Runnable may be passed into the Thread's constructor and this class's run() method will get called.

For example:


Constructor & Destructor Documentation

VCF::Thread::Thread  ) 
 

VCF::Thread::Thread const bool &  autoDelete  ) 
 

VCF::Thread::Thread Runnable runnableObject,
const bool &  autoDelete
 

creates a thread with the attached runnableObject (if appropriate)

Parameters:
Runnable the runnableObject the thread will use. By default this is NULL, which means the Thread's run method has been overridden in a derived class.
bool indicates whose responsibility it is to clean up after the thread is stopped. If autoDelete is true then the thread instance will clean up for itself, if autoDelete is false, then it is the caller's responsibility to clean up

VCF::Thread::Thread Runnable runnableObject,
const bool &  autoDeleteRunnable,
const bool &  autoDelete
 

Creates a thread with a runnable object, and allows the thread to automatically delete the runnable if appropriate.

VCF::Thread::Thread Runnable runnableObject  ) 
 

virtual VCF::Thread::~Thread  )  [virtual]
 


Member Function Documentation

bool VCF::Thread::canAutoDelete  )  [inline]
 

can the thread auto delete itself ?

Returns:
bool true if the thread will auto delete itself. Determined by the parameters passed into the thread's constructor

bool VCF::Thread::canContinue  )  [inline]
 

can the thread continue to execute ?

Returns:
bool true if the thread can safely continue to execute, otherwise false indicating it should stop executing.

static Thread* VCF::Thread::getMainThread  )  [static]
 

Returns the main or primary thread for a program.

There is always at least one thread (what you might say is the "primary" thread of execution) that an executable program will create when it is started up. This function will return that primary thread. You don't create it, and you don't destroy it, that's handled by the framework.

uint32 VCF::Thread::getOwningProcessID  ) 
 

returns the process ID that this thread is part of

ThreadPeer* VCF::Thread::getPeer  )  [inline]
 

virtual OSHandleID VCF::Thread::getPeerHandleID  )  [virtual]
 

Implements VCF::Waitable.

RunLoopPtr::Shared VCF::Thread::getRunLoop  ) 
 

bool VCF::Thread::getRunsWithExceptionHandler  )  [inline]
 

Returns whether or not the thread's run() method is wrapped with an try/catch block.

Returns:
bool True if the thread's run() method is wrapped in an try/catch block. False if it's not.

uint32 VCF::Thread::getThreadID  ) 
 

returns the thread associated with this thread of execution

void VCF::Thread::internal_initBeforeRun  ) 
 

Called by the thread peer implementation.

Initializes the thread with the thread manager.

bool VCF::Thread::internal_isStopped  )  [inline]
 

for thread peer's usage only - called to see if the thread is being shutdown via the stop() method.

bool VCF::Thread::internal_run  ) 
 

bool VCF::Thread::isActive  ) 
 

Returns TRUE if thread is running, FALSE if not.

virtual bool VCF::Thread::run  )  [virtual]
 

run method for the thread.

Overide this method to provide additional functionality. If runnableObject_ is non NULL then it's run() will be called in here.

Implements VCF::Runnable.

Reimplemented in VCF::PoolThread.

void VCF::Thread::setRunsWithExceptionHandler bool  val  )  [inline]
 

Sets the variable that determines whether or not the thread's run() method is wrapped in an try/catch block.

If this is set to true, then the run() method will have a try/catch block around it, which will catch all exceptions thrown, preventing exceptions from propagating outside the threads execution. If this is set to false, the default value, then no try/catch block is used when the thread's run() method is invoked. This means that exceptions thrown will cause problems if not caught within the execution of the thread.

Note that this only makes sense to call before the thread's start() method is called. Once start() is called, the thread's run() will be executed and calling this method at that point will have no effect.

void VCF::Thread::sleep uint32  milliseconds  ) 
 

causes the thread the thread to sleep for the specified number of milliseconds

Parameters:
uint32 - the number of milliseconds to sleep

bool VCF::Thread::start  ) 
 

Starts (or resumes) a thread running.

If you want to protect the thread's execution within a try/catch block, make sure to call setRunsWithExceptionHandler(true), prior to calling this method.

See also:
setRunsWithExceptionHandler

virtual void VCF::Thread::stop  )  [virtual]
 

gracefully stops the thread and shuts it down, releasing any OS resources associated with the thread.

Once a thread is stopped that thread instance may NOT be started again. If the thread is set for automatic deletion this is where it will happen. This method will block until the thread is stopped.

Implements VCF::Runnable.

virtual Waitable::WaitResult VCF::Thread::wait uint32  milliseconds  )  [virtual]
 

Implements VCF::Waitable.

virtual WaitResult VCF::Thread::wait  )  [virtual]
 

Implements VCF::Waitable.


Member Data Documentation

bool VCF::Thread::autoDelete_ [protected]
 

bool VCF::Thread::autoDeleteRunnable_ [protected]
 

bool VCF::Thread::canContinue_ [protected]
 

Thread* VCF::Thread::mainThread [static, protected]
 

ThreadPeer* VCF::Thread::peer_ [protected]
 

RunLoopPtr::Shared VCF::Thread::runLoop_ [protected]
 

Runnable* VCF::Thread::runnableObject_ [protected]
 

bool VCF::Thread::runWithExceptionBlock_ [protected]
 

bool VCF::Thread::stopped_ [protected]
 


The documentation for this class was generated from the following file:
   Comments or Suggestions?    License Information