A thread of execution. More...
#include <Thread.h++>

Public Member Functions | |
| Thread (bool detached=false, size_t stackSize=0) | |
| Construct a new Thread. | |
| Thread (Runnable *runnable, bool detached=false, size_t stackSize=0) | |
| Construct a new Thread with a Runnable object. | |
| virtual | ~Thread () throw () |
| Destructor. | |
| virtual void | start () throw () |
| Start executing the thread. | |
| virtual void | stop () throw () |
| Stop execution of the thread. | |
| bool | join () throw () |
| Wait for the thread to terminate. | |
| bool | isRunning () const throw () |
| Test if the thread is currently running. | |
| bool | isDetached () const throw () |
| Test if the thread is detached. | |
| void | setPriority (Priority priority) throw () |
| Set the thread priority. | |
| Priority | getPriority () const throw () |
| Get the thread priority. | |
| void | setName (const String &name) throw () |
| Set the name of this thread. | |
| String | getName () const throw () |
| Get the name of this thread. | |
Static Public Member Functions | |
| static void | sleep (timespan_ms_t msec) throw () |
| Suspend the calling thread for the given time interval. | |
| static Thread * | currentThread () |
| Obtain a pointer to the Thread object for the calling thread. | |
| static ThreadID | currentThreadID () throw () |
| Get the calling thread's thread ID. | |
Protected Member Functions | |
| virtual void | run () |
| Main function. | |
| virtual void | cleanup () |
| Cleanup function. | |
| bool | trySleep (timespan_ms_t msec) throw () |
| Suspend the thread for the given time interval, returning early if the thread was cancelled via a call to stop(). | |
| bool | testCancel () throw () |
| Test for asynchronous cancellation requests. | |
| void | yield () throw () |
| Yield the CPU to (potentially) another thread. | |
Static Protected Member Functions | |
| static void | exit () throw () |
| Exit (terminate) the calling thread. | |
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. |
| ~Thread | ( | ) | throw () [virtual] |
Destructor.
| void cleanup | ( | ) | [protected, virtual] |
Cleanup function.
This function will be executed by the thread just prior to termination. The default implementation is a no-op.
Reimplemented in PulseTimer, and SocketMuxer.
| Thread * currentThread | ( | ) | [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.
| ccxx::ThreadID currentThreadID | ( | ) | throw () [static] |
Get the calling thread's thread ID.
| void exit | ( | ) | throw () [static, protected] |
Exit (terminate) the calling thread.
| String getName | ( | ) | const throw () [inline] |
Get the name of this thread.
| Priority getPriority | ( | ) | const throw () |
Get the thread priority.
| bool isDetached | ( | ) | const throw () [inline] |
Test if the thread is detached.
| bool isRunning | ( | ) | const throw () |
Test if the thread is currently running.
| bool join | ( | ) | throw () |
Wait for the thread to terminate.
| void run | ( | ) | [protected, virtual] |
Main function.
Thread execution begins in this function. The default implementation does nothing.
Implements Runnable.
Reimplemented in DirectoryWatcher, PulseTimer, and SocketMuxer.
| void setName | ( | const String & | name | ) | throw () [inline] |
Set the name of this thread.
| void setPriority | ( | Priority | priority | ) | throw () |
Set the thread priority.
| void sleep | ( | timespan_ms_t | msec | ) | throw () [static] |
Suspend the calling thread for the given time interval.
| msec | The number of milliseconds to sleep. |
| void start | ( | ) | throw () [virtual] |
| void stop | ( | ) | throw () [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.
| bool testCancel | ( | ) | throw () [protected] |
Test for asynchronous cancellation requests.
| bool trySleep | ( | timespan_ms_t | msec | ) | throw () [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. |
| void yield | ( | ) | throw () [protected] |
Yield the CPU to (potentially) another thread.
1.6.3