libcommonc++
0.7
|
A thread of execution. More...
#include <Thread.h++>
Public Member Functions | |
Thread (bool detached=false, size_t stackSize=0) | |
Construct a new Thread. More... | |
Thread (Runnable *runnable, bool detached=false, size_t stackSize=0) | |
Construct a new Thread with a Runnable object. More... | |
virtual | ~Thread () |
Destructor. More... | |
virtual void | start () |
Start executing the thread. More... | |
virtual void | stop () |
Stop execution of the thread. More... | |
bool | join () |
Wait for the thread to terminate. More... | |
bool | isRunning () const |
Test if the thread is currently running. More... | |
bool | isDetached () const |
Test if the thread is detached. More... | |
void | setPriority (Priority priority) |
Set the thread priority. More... | |
Priority | getPriority () const |
Get the thread priority. More... | |
void | setName (const String &name) |
Set the name of this thread. More... | |
String | getName () const |
Get the name of this thread. More... | |
Static Public Member Functions | |
static void | sleep (timespan_ms_t msec) |
Suspend the calling thread for the given time interval. More... | |
static Thread * | currentThread () |
Obtain a pointer to the Thread object for the calling thread. More... | |
static ThreadID | currentThreadID () |
Get the calling thread's thread ID. More... | |
Protected Member Functions | |
virtual void | run () |
Main function. More... | |
virtual void | cleanup () |
Cleanup function. More... | |
bool | trySleep (timespan_ms_t msec) |
Suspend the thread for the given time interval, returning early if the thread was cancelled via a call to stop(). More... | |
bool | testCancel () |
Test for asynchronous cancellation requests. More... | |
void | yield () |
Yield the CPU to (potentially) another thread. More... | |
Static Protected Member Functions | |
static void | exit () |
Exit (terminate) the calling thread. More... | |
A thread of execution.
Thread can be used in one of two ways:
A thread can be detached or joinable. A joinable thread continues to exist after it has finished executing; its resources must be reclaimed by calling the join() method. A joinable thread can be started and stopped multiple times.
Thread | ( | bool | detached = false , |
size_t | stackSize = 0 |
||
) |
Construct a new Thread.
detached | A flag indicating whether the thread will be created in a detached state. |
stackSize | The stack size for the thread, in bytes. A value of 0 indicates that the default stack size should be used. |
Construct a new Thread with a Runnable object.
runnable | The runnable object whose run() method will be executed in this thread. |
detached | A flag indicating whether the thread will be created in a detached state. |
stackSize | The stack size for the thread, in bytes. A value of 0 indicates that the default stack size should be used. |
|
virtual |
Destructor.
|
protectedvirtual |
Cleanup function.
This function will be executed by the thread just prior to termination. The default implementation is a no-op.
Reimplemented in SocketSelector, and PulseTimer.
|
static |
Obtain a pointer to the Thread object for the calling thread.
If the calling thread is the main thread, or some other thread that was not created via commonc++, a NULL pointer is returned. Never delete the object returned by this method.
|
static |
Get the calling thread's thread ID.
|
staticprotected |
Exit (terminate) the calling thread.
|
inline |
Get the name of this thread.
Priority getPriority | ( | ) | const |
Get the thread priority.
|
inline |
Test if the thread is detached.
bool isRunning | ( | ) | const |
Test if the thread is currently running.
bool join | ( | ) |
Wait for the thread to terminate.
|
protectedvirtual |
Main function.
Thread execution begins in this function. The default implementation does nothing.
Implements Runnable.
Reimplemented in SocketSelector, PulseTimer, and DirectoryWatcher.
|
inline |
Set the name of this thread.
void setPriority | ( | Priority | priority | ) |
Set the thread priority.
|
static |
Suspend the calling thread for the given time interval.
msec | The number of milliseconds to sleep. |
|
virtual |
|
virtual |
Stop execution of the thread.
The thread is not forcibly killed; instead, an asynchronous cancellation request is posted to the thread. If the thread is not running, the call has no effect.
|
protected |
Test for asynchronous cancellation requests.
|
protected |
Suspend the thread for the given time interval, returning early if the thread was cancelled via a call to stop().
msec | The number of milliseconds to sleep. |
|
protected |
Yield the CPU to (potentially) another thread.