|
|
This abstract class realizes threads based on Linux's pthreads. The user of this class has to implement run(). Synchronization is implemented by inheriting Synchronizable. IMPORTANT: Do *not* use Thread methods within async signal handlers. This may cause deadlocks. See PThread's pthread_mutex_lock man-page, section "Async Signal Safety" for more information!
See also: Synchronizable
Thread (const cardinal flags = ThreadCancelAsynchronous) |
Constructor. A new thread will be created but *not* started! To start the new thread, call start().
Parameters:
flags | Flags for the thread to be created |
See also: start
~Thread () |
Destructor. The thread will be stopped (if running) and deleted.
inline bool running () |
Check, if the thread is running.
Returns: true, if the thread is running, false otherwise
card64 delay (const card64 delayTimeout, const bool interruptable = false) |
Delay execution of current thread for a given timeout. This function uses nanosleep(), so no signals are affected.
Parameters:
delayTime | Timeout in microseconds. |
interruptable | true, if delay may be interrupted by signals; false otherwise. |
Returns: Remaining delay, if interrupted; 0 otherwise.
bool start () |
Start the thread, if not already started.
Returns: true, if the thread has been started; false, if not.
void stop () |
Stop the thread, if not already stopped. If the thread flag ThreadCancelAsynchronous is set, it will be stopped immediately. If the flag ThreadCancelDeferred is set, it will be stopped when a cancellation point is reached (-> see pthreads documentation). testCancel() is such a cancellation point.
See also: testCancel
cardinal join () |
Wait for the thread to be finished.
void cancel () |
Cancel the thread.
void suspend () |
Suspend the thread. Note: The thread will not be suspended immediately! The thread will be suspended, when it reaches the next testSuspension() call! => To implement suspendable threads, testSuspension() must be called by the thread regularly!!!
See also: testSuspension
void resume () |
Resume a suspended thread.
void testCancel () |
Test for cancellation. If the thread received a cancel signal, it will be cancelled.
bool testSuspension () |
Test for suspension. If the thread received a suspension signal, it will be suspended.
Returns: true, if the thread was suspended.
inline void exit (const cardinal result = 0) |
Exit current thread.
Parameters:
result | Result to return. |
inline void yield () |
Voluntarily move current thread to end of queue of threads waiting for CPU time (sched_yield() call). This will result in scheduling to next waiting thread, if there is any.
void run () |
The virtual run() method, which contains the thread's implementation. It has to be implemented by classes, which inherit Thread.