![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
The Thread class itself. More...
Inherited by InputTaskChannelInternal< SampleType, InterpTypeCode >::InputTask, ObjectMemoryDeferFree, and ObjectMemoryPools.
Public Member Functions | |
ResultCode | wait () throw () |
Waits for the thread to exit. | |
bool | isRunning () throw () |
Returns true if the thread is running, otherwise false . | |
ResultCode | setShouldExit () throw () |
Signals that the thread should exit. | |
ResultCode | setShouldExitAndWait (const double interval=0.000001) throw () |
Signals that the thread should exit then waits for it to exit. | |
bool | getShouldExit () throw () |
Returns true if the thread has been signalled to exit, otherwise false . | |
Threading::ID | getID () throw () |
Get this thread's ID. | |
virtual ResultCode | run ()=0 |
The run() function: you must implement this in your sublcass. | |
Static Protected Member Functions | |
static ResultCode | sleep (const double seconds) throw () |
A shortcut for Threading::sleep() | |
static ResultCode | yield () throw () |
A shortcut for Threading::yield() |
The Thread class itself.
You must inherit form this and implement the run() function. Then call start().
class MyThread: public Threading::Thread { public: ResultCode run() { while (getShouldExit() == false) { //... do stuff here ... } return 0; // success } };
Then from another thread (e.g., in main()):
... MyThread myThread; myThread.start(); ...
Threading::ID Threading::Thread::getID | ( | ) | throw () |
Get this thread's ID.
bool Threading::Thread::getShouldExit | ( | ) | throw () |
Returns true
if the thread has been signalled to exit, otherwise false
.
This is thread-safe.
bool Threading::Thread::isRunning | ( | ) | throw () |
Returns true
if the thread is running, otherwise false
.
This is thread-safe.
virtual ResultCode Threading::Thread::run | ( | ) | [pure virtual] |
The run() function: you must implement this in your sublcass.
ResultCode Threading::Thread::setShouldExit | ( | ) | throw () |
Signals that the thread should exit.
The run() function should be checking getShouldExit() regularly to determine if it should exit. This is thread-safe.
ResultCode Threading::Thread::setShouldExitAndWait | ( | const double | interval = 0.000001 | ) | throw () |
Signals that the thread should exit then waits for it to exit.
This is thread-safe but blocks the calling thread until the other thread has exited.
interval | The time interval between checks for the thread to exit. |
ResultCode Threading::Thread::wait | ( | ) | throw () |
Waits for the thread to exit.
You should call setShouldExit() then call this function to block until the thread exits. Or you could run your own loop checking isRunning() until that returns false to simulate the same behviour.