YGP::Thread Class Reference

Class to execute a certain function in a thread. More...

Inherited by YGP::OThread< T >.

List of all members.

Public Types

typedef void *(* THREAD_FUNCTION )(void *)

Public Member Functions

virtual ~Thread ()
void * getArgs () const
unsigned long getID () const

Static Public Member Functions

static Threadcreate (THREAD_FUNCTION fnc, void *pArgs) throw (YGP::ExecError)
static Threadcreate2 (THREAD_FUNCTION fnc, void *pArgs) throw (YGP::ExecError)
static unsigned long currentID ()

Protected Member Functions

 Thread ()
 Thread (THREAD_FUNCTION fnc, void *pArgs) throw (YGP::ExecError)
void ret (void *rc) const
void init (THREAD_FUNCTION fnc, void *pArgs) throw (YGP::ExecError)

Protected Attributes

void * pArgs_

Termination of the thread

void allowCancelation (bool allow=true)
void cancel ()
void isToCancel () const
static void * waitForThread (const Thread &id)
static void * waitForThread (unsigned long threadID)


Detailed Description

Class to execute a certain function in a thread.

There are two create-functions: The first calles the passed function with the parameters directly; the second passed a pointer to the created thread and enables to get the paramters with its getArgs-method. This enables controlling the thread.


Member Typedef Documentation

typedef void*(* YGP::Thread::THREAD_FUNCTION)(void *)

Declaration of prototype of callback.


Constructor & Destructor Documentation

YGP::Thread::~Thread (  )  [virtual]

Destructor.

YGP::Thread::Thread (  )  [protected]

Defaultconstructor; create the object but no actual thread.

YGP::Thread::Thread ( THREAD_FUNCTION  fnc,
void *  pArgs 
) throw (YGP::ExecError) [protected]

Constructor; Create object and a thread and passes pArgs as arguments.

Parameters:
fnc Function to be called in the thread
pArgs Pointer to argument(s)
Exceptions:
YGP::ExecError describing the error


Member Function Documentation

void YGP::Thread::allowCancelation ( bool  allow = true  ) 

Terminates the thread.

Remarks:
Note that not all plattforms (e.g. Windows) support to cancel a thread; in such a case the thread must check itself, if it should be canceled.

void YGP::Thread::cancel (  ) 

Terminates the thread.

Remarks:
Note that not all plattforms (e.g. Windows) support to cancel a thread; in such a case the thread must check itself, if it should be canceled.

static Thread* YGP::Thread::create ( THREAD_FUNCTION  fnc,
void *  pArgs 
) throw (YGP::ExecError) [inline, static]

Creates a new thread; the argument is passed directly to the thread function.

Parameters:
fnc Thread function to execute
pArgs Argument to the thread

static Thread* YGP::Thread::create2 ( THREAD_FUNCTION  fnc,
void *  pArgs 
) throw (YGP::ExecError) [inline, static]

Creates a new thread; a pointer to the thread ID is passed to the thread function.

Parameters:
fnc Thread function to execute
pArgs Argument to the thread

static unsigned long YGP::Thread::currentID (  )  [inline, static]

Get the ID of the currently running thread.

void* YGP::Thread::getArgs (  )  const [inline]

Returns the argument passed to the thread.

unsigned long YGP::Thread::getID (  )  const [inline]

Get the ID of the thread.

void YGP::Thread::init ( THREAD_FUNCTION  fnc,
void *  pArgs 
) throw (YGP::ExecError) [protected]

Creates the actual thread from the passed function.

Parameters:
fnc Function to be called in the thread
pArgs Pointer to parameters
Exceptions:
YGP::ExecError describing the error

void YGP::Thread::isToCancel (  )  const

Checks if the thread should be canceled and does so, if yes.

void YGP::Thread::ret ( void *  rc  )  const [protected]

Sets the return value for the thread.

Parameters:
rc Returncode

void * YGP::Thread::waitForThread ( unsigned long  id  )  [static]

Waits for the thread with the passed ID to terminate.

Parameters:
id Thread to wait for
Returns:
void* The returncode of the thread

void * YGP::Thread::waitForThread ( const Thread id  )  [static]

Waits for the passed thread to terminate.

Parameters:
id Thread to wait for
Returns:
void* The returncode of the thread


Member Data Documentation

void* YGP::Thread::pArgs_ [protected]

Pointer to (array of) arguments to the thread.


The documentation for this class was generated from the following files:

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:28 2009 by doxygen 1.5.8