Om
1.0.0
A universal framework for multimedia simulation
|
A class that provides a system-independent abstraction for a thread of execution. More...
#include <omThreadBase.h>
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... | |
ThreadBase & | operator= (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... | |
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).
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 |
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.
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.
|
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 |
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.
milliseconds | - the number of milliseconds until execution will resume. |
|
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.
seconds | - the number of seconds until execution will resume. |
|
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 |
Terminate the current calling thread.
This method prematurely terminates the calling thread.
|
static |
Return the ID of the calling thread.
|
protected |
Start this thread object's execution.
The method returns whether or not starting the thread was successful.
|
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.
|
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 &)>.