class Thread

Thread. More...

Contains pure virtuals
Full nameCoral::Thread
Definition#include <thread.h>
InheritsCoral::Synchronizable
Inherited byNetworkMonitor, RTCPReceiver, RTPReceiver, TimedThread, AdvancedAudioDecoder, CongestionManagerClient, CongestionManager, CongestionMonitor, NetLogWriter, RoundTripTimePinger, RTCPAbstractServer, AudioServer, RTCPSender, RTPSender, TrafficShaperSingleton
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Members

Protected Members


Detailed Description

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:
flagsFlags for the thread to be created

See also: start

~Thread ()
[virtual]

Destructor. The thread will be stopped (if running) and deleted.

inline bool running ()
[const]

Check, if the thread is running.

Returns: true, if the thread is running, false otherwise

card64 delay (const card64 delayTimeout, const bool interruptable = false)
[static]

Delay execution of current thread for a given timeout. This function uses nanosleep(), so no signals are affected.

Parameters:
delayTimeTimeout in microseconds.
interruptabletrue, if delay may be interrupted by signals; false otherwise.

Returns: Remaining delay, if interrupted; 0 otherwise.

bool start ()
[virtual]

Start the thread, if not already started.

Returns: true, if the thread has been started; false, if not.

void stop ()
[virtual]

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 ()
[virtual]

Cancel the thread.

void suspend ()
[virtual]

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 ()
[virtual]

Resume a suspended thread.

void testCancel ()
[protected virtual]

Test for cancellation. If the thread received a cancel signal, it will be cancelled.

bool testSuspension ()
[protected virtual]

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)
[protected static]

Exit current thread.

Parameters:
resultResult to return.

inline void yield ()
[protected static]

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 ()
[protected pure virtual]

The virtual run() method, which contains the thread's implementation. It has to be implemented by classes, which inherit Thread.