#include <mcllib/MCThread.h>
Inheritance diagram for MCThread:
Public Types | |
enum | EPriority { THRPRILOW, THRPRINORMAL, THRPRIHIGH, THRPRIURGENT } |
Thread priority. More... | |
enum | EScope { THRSCOPELOCAL, THRSCOPEGLOBAL, THRSCOPEBOUND } |
Thread scope. More... | |
enum | EState { THRSTATEJOIN, THRSTATENOJOIN } |
Thread state. More... | |
enum | EType { THRTYPEUSER, THRTYPESYS } |
Thread type. More... | |
Public Member Functions | |
mcthreadid_t | getId () const |
Get the unique id of the thread. | |
const MCString & | getName () const |
Get the name of the thread as specified at construction time. | |
void | join () |
Wait until this thread has finished working. | |
MCThread (const MCString &name) | |
Construct a named thread object. | |
MCThread () | |
Construct an unamed thread object. | |
void | setInterrupt () |
Interrupt the thread if it is interruptable. | |
void | setPriority (EPriority pri) |
Set the priority of thread. | |
void | start (MCRunnable *pRunnable, EType type=THRTYPEUSER, EScope scope=THRSCOPELOCAL, EState state=THRSTATEJOIN, EPriority pri=THRPRINORMAL, mcstacksize_t sz=0) |
Start a thread running. | |
Static Public Member Functions | |
void | clearInterrupt () |
Clear any pending interrupt on the current thread. | |
MCThread | getCurrentThread () |
Obtain an MCThread object for the calling thread. | |
MCRefPtr< MCThreadData > | getData (mcthreaddatakey_t index) |
Get the thread data stored for an index. | |
mcthreaddatakey_t | getDataIndex (const MCString &key) |
Get a thread data index. | |
void | setData (mcthreaddatakey_t index, MCThreadData *pData) |
Set (store) the thread data for an index. | |
void | setDataAll (mcthreaddatakey_t index, MCThreadData *pData) |
Set (store) the thread data for an index for the current thread and all future threads. | |
void | sleep (mcinterval_t interval) |
Sleep for a number of milliseconds. | |
void | yield () |
Yield (give up the CPU) to another thread. |
Threads are used in conjunction with runnables. A runnable provides a run function which is called by the thread object. The runnable is a light-weight interface. The same thread object can be used (at different times) to run different runnables.
|
Thread priority.
|
|
Thread scope.
|
|
Thread state.
|
|
Thread type.
|
|
Construct an unamed thread object. The name is set to [UNKNOWN] |
|
Construct a named thread object.
|
|
Clear any pending interrupt on the current thread. If the current thread is marked as interrupted, clear the interrupt |
|
Obtain an MCThread object for the calling thread.
|
|
Get the thread data stored for an index.
|
|
Get a thread data index.
|
|
Get the unique id of the thread. Each thread has an id which is unique within the process in which it is running, whilst it continues to run and references exist to it. Once a thread has terminated and no references exist to it, the thread id may be re-used by another thread.
|
|
Get the name of the thread as specified at construction time. If no name was specified a system default name will be supplied. This is useful when debugging multi-threaded applications.
|
|
Wait until this thread has finished working. Has no effect if the thread has not been start()ed. An exception will be thrown if the thread cannot be joined. |
|
Set (store) the thread data for an index.
|
|
Set (store) the thread data for an index for the current thread and all future threads.
|
|
Interrupt the thread if it is interruptable. Has no effect if the thread has not been start()ed. An exception will be thrown if the thread cannot be interrupted. |
|
Set the priority of thread. Has no effect if the thread has not been start()ed.
|
|
Sleep for a number of milliseconds. The current thread (the one calling sleep) is put to sleep.
|
|
Start a thread running. The start function returns once the thread has been started. If a thread cannot be started an exception is thrown. The run() function of the runnable will run concurrently with the thread that called the start function. Note that the run() function may not have been called before start returns although a thread will have been created and the run() function scheduled to begin.
|
|
Yield (give up the CPU) to another thread. The current thread (the one calling yield) yields to some other thread |