class Thread

Thread. More...

Contains pure virtuals
Full nameCoral::Thread
Definition#include <thread.h>
InheritsCoral::Synchronizable [public ]
Inherited byMultiTimerThread, SCTPSocketMaster
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Public Static Methods

Public Members

Protected Methods

Protected Static Methods

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

static const cardinal TF_CancelAsynchronous

TF_CancelAsynchronous

static const cardinal TF_CancelDeferred

TF_CancelDeferred

static const cardinal TCS_CancelEnabled

TCS_CancelEnabled

static const cardinal TCS_CancelDisabled

TCS_CancelDisabled

static const cardinal TCS_CancelDeferred

TCS_CancelDeferred

 Thread (const char* name = "Thread", const cardinal flags = TF_CancelDeferred)

Thread

Constructor. A new thread will be created but *not* started! To start the new thread, call start().

Parameters:
nameThread name.
flagsFlags for the thread to be created.

See also: start

 ~Thread ()

~Thread

[virtual]

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

inline bool  running ()

running

[const]

Check, if the thread is running.

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

inline pid_t  getPID ()

getPID

[const]

Get thread's PID.

card64  delay (const card64 delayTimeout, const bool interruptable = false)

delay

[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 (const char* name = NULL)

start

[virtual]

Start the thread, if not already started.

Parameters:
nameThread name (NULL for default).

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

void*  stop ()

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.

Returns: Return value from stopped thread.

See also: testCancel

void*  join ()

join

Wait for the thread to be finished.

Returns: Return value from joined thread.

void  cancel ()

cancel

[virtual]

Cancel the thread.

inline cardinal  setCancelState (const cardinal state)

setCancelState

[static]

Enable or disable cancelability of calling thread. The previous state is returned. Important note: The result may include additional state information, depending on the operating system. This state can be restored by giving this complete information to a setCancelState() call.

Parameters:
enabledTCS_CancelEnable to enable cancellation; TCS_CancelDisable otherwise.

Returns: Old state.

Reimplemented from Synchronizable.

static Synchronizable SyncSetLock

SyncSetLock

static Synchronizable MemoryManagementLock

MemoryManagementLock

static set<Thread*> ThreadSet

ThreadSet

void  testCancel ()

testCancel

[protected virtual]

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

inline void  exit (void* result = NULL)

exit

[protected static]

Exit current thread.

Parameters:
resultResult to return.

inline void  yield ()

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 ()

run

[protected pure virtual]

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

pthread_t PThread

PThread

[protected]

pid_t PID

PID

[protected]