Om  1.0.0
A universal framework for multimedia simulation
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
om::threads::ThreadBase Class Referenceabstract

A class that provides a system-independent abstraction for a thread of execution. More...

#include <omThreadBase.h>

Inheritance diagram for om::threads::ThreadBase:
om::threads::FunctionThread< void()> om::threads::FunctionThread< void(const om::graphics::devices::GraphicsDeviceType &deviceType, const om::graphics::devices::RenderedPixelFormat &, const om::graphics::devices::GraphicsContextFlags &)> om::threads::FunctionThread< Signature >

Public Member Functions

 ThreadBase ()
 Create a default thread that is not yet running. More...
 
 ThreadBase (const ThreadBase &other)
 Create a new thread that is a copy of another thread. More...
 
virtual ~ThreadBase ()
 Destroy this thread object. More...
 
ThreadBaseoperator= (const ThreadBase &other)
 Copy the attributes of one thread to this thread. More...
 
Bool stop ()
 Forcibly end the execution of a thread. More...
 
Bool isRunning () const
 Get whether or not a thread is currently running. More...
 
ThreadID getID () const
 Return the ID of this thread. More...
 
ThreadPriority getPriority (const ThreadPriority &newPriority)
 Return an object describing the current scheduling priority for this thread. More...
 
Bool setPriority (const ThreadPriority &newPriority)
 Set the scheduling priority for this thread. More...
 

Static Public Member Functions

static void sleepMs (UInt milliseconds)
 Sleep the calling thread for the specified number of milliseconds. More...
 
static void sleep (double seconds)
 Sleep this thread for the specified number of seconds. More...
 
static void yield ()
 Relinquish the calling thread's CPU time until is it rescheduled. More...
 
static void exit ()
 Terminate the current calling thread. More...
 
static ThreadID getCurrentID ()
 Return the ID of the calling thread. More...
 

Protected Member Functions

Bool startThread ()
 Start this thread object's execution. More...
 
Bool joinThread ()
 Wait indefinitely to join a thread when it dies. More...
 
virtual void run ()=0
 Start the execution of subclass client code on a new thread. More...
 

Detailed Description

A class that provides a system-independent abstraction for a thread of execution.

This is the base class for a platform-independent thread. Subclasses implement the run() method, providing a better user interface to thread initialization. They can provide more complex functionality (such as a worker thread).

Constructor & Destructor Documentation

om::threads::ThreadBase::ThreadBase ( )

Create a default thread that is not yet running.

om::threads::ThreadBase::ThreadBase ( const ThreadBase other)

Create a new thread that is a copy of another thread.

This merely copies any attributes of the other thread, the new thread object still refers to a different OS thread than the copied object.

virtual om::threads::ThreadBase::~ThreadBase ( )
virtual

Destroy this thread object.

This doesn't stop the thread if it is currently running, only destroys any way of controlling or joining the thread - it is orphaned and will continue until it returns on its own.

Member Function Documentation

ThreadBase& om::threads::ThreadBase::operator= ( const ThreadBase other)

Copy the attributes of one thread to this thread.

This doesn't stop the thread if it is currently running, only destroys any way of controlling or joining the thread - it is orphaned and will continue until it returns on its own. This operator initializes the thread object with any attributes of the other thread. The newly assigned thread is not running.

Bool om::threads::ThreadBase::stop ( )

Forcibly end the execution of a thread.

This method forcibly stops the execution of a thread object if it is currently running. The use of this method is not recommended in general. Calling this method can result in memory not being correctly freed and other undefinend behavior.

Bool om::threads::ThreadBase::isRunning ( ) const
inline

Get whether or not a thread is currently running.

ThreadID om::threads::ThreadBase::getID ( ) const

Return the ID of this thread.

ThreadPriority om::threads::ThreadBase::getPriority ( const ThreadPriority newPriority)

Return an object describing the current scheduling priority for this thread.

Bool om::threads::ThreadBase::setPriority ( const ThreadPriority newPriority)

Set the scheduling priority for this thread.

The method returns whether or not the thread's priority was successfully changed.

static void om::threads::ThreadBase::sleepMs ( UInt  milliseconds)
static

Sleep the calling thread for the specified number of milliseconds.

The calling thread yeilds it's position in the operating system's process queue to another thread and halts execution until the specified number of milliseconds has elapsed.

Parameters
milliseconds- the number of milliseconds until execution will resume.
static void om::threads::ThreadBase::sleep ( double  seconds)
static

Sleep this thread for the specified number of seconds.

The calling thread yeilds it's position in the operating system's process queue to another thread and halts execution until the specified number of seconds has elapsed.

Parameters
seconds- the number of seconds until execution will resume.
static void om::threads::ThreadBase::yield ( )
static

Relinquish the calling thread's CPU time until is it rescheduled.

The calling thread yeilds it's position in the operating system's process queue to another thread and halts execution until it is again rescheduled for execution.

static void om::threads::ThreadBase::exit ( )
static

Terminate the current calling thread.

This method prematurely terminates the calling thread.

static ThreadID om::threads::ThreadBase::getCurrentID ( )
static

Return the ID of the calling thread.

Bool om::threads::ThreadBase::startThread ( )
protected

Start this thread object's execution.

The method returns whether or not starting the thread was successful.

Bool om::threads::ThreadBase::joinThread ( )
protected

Wait indefinitely to join a thread when it dies.

This method stops the execution of the calling thread indefinitely until the thread object has finished running. Use this with caution, as it can cause a program to lock up while it waits for the thread to finish.

The method returns whether or not joining the thread was successful.

virtual void om::threads::ThreadBase::run ( )
protectedpure virtual

Start the execution of subclass client code on a new thread.

This virtual method is called by the ThreadBase class when a new thread is started using the startThread() method. A subclass should override this method and provide its own custom hook into the new thread.

Implemented in om::threads::FunctionThread< Signature >, om::threads::FunctionThread< void()>, and om::threads::FunctionThread< void(const om::graphics::devices::GraphicsDeviceType &deviceType, const om::graphics::devices::RenderedPixelFormat &, const om::graphics::devices::GraphicsContextFlags &)>.


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