Thread

Functions

CID

GetClassID

void

ChangeToAnotherThread

void *

As

const void *

As

class T_As

As

class T_As

As

Thread

~Thread

void

Setup

RED_RC

Run

void

StopRun

RED_RC

Close

bool

IsValid

bool

IsRunning

void *

GetUserArgument

pthread_t

GetHandle

RED_RC

ReturnedCode

RED_RC

WaitForTermination

Detailed Description

class Thread : public RED::Object

Encapsulation of threading services.

@related Backbone

Public Functions

virtual void *As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

virtual const void *As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

template<class T_As>
inline T_As *As()
template<class T_As>
inline const T_As *As() const
Thread()

Construction method.

~Thread()

Destruction method.

void Setup(THREAD_CALLBACK iCallback, void *iCallbackArg = NULL)

Defines the thread’s parameters.

Parameters
  • iCallback – pointer to the callback that will be called by the thread.

  • iCallbackArg – Optional pointer to the callback user argument.

RED_RC Run(THREAD_PRIORITY iPriority = TP_NORMAL)

Runs the thread.

When this method is called, the thread is run and the user callback is called with the thread being passed as an argument.

Parameters

iPriority – optional thread priority.

Returns

RED_OK on success,

RED_WORKFLOW_ERROR if the thread’s resources are still used, and have not been released,

RED_FAIL if we have no valid callback.

void StopRun(RED_RC iRC)

Prepares thread exit.

This method must be called from the threaded method. It indicates that the thread will terminate after this method. Practically, the threaded method must return after this call. Note that the thread must be closed (from the launching thread) after it has returned to release all its resources.

Parameters

iRC – Return code value of the thread.

RED_RC Close()

Releases threading resources.

This method must be called before the thread can be run again. The thread’s resources are released. The thread must have ended before this method can be called.

Returns

RED_OK on success,

RED_FAIL otherwise.

inline bool IsValid() const

Is the thread valid?

Returns

true if we’re between a Run and a Close. This does not indicate whether the thread has exit or not.

inline bool IsRunning() const

Is the thread running?

Return true if the thread is running now. This means that the thread has not been closed.

Returns

true if the thread is running false otherwise.

inline void *GetUserArgument() const
Returns

The address of the user argument.

inline pthread_t GetHandle() const
Returns

the LINUX/MAC OS thread handle.

inline RED_RC ReturnedCode() const

Gets the thread’s return code.

Returns

The current thread’s return code.

RED_RC WaitForTermination()

Blocks the caller until the given thread terminates.

Returns

RED_OK on success,

RED_FAIL if the wait ended in error. This may be related to a thread that has not been terminated using REDThread::Exit.

Public Static Functions

static inline RED::CID GetClassID()
static void ChangeToAnotherThread()

Stops consuming time. Switch to another running thread.

This call is used to stop a thread from running right at that time. Another thread will use the processor until the caller’s turn comes in again. This method is only effective on Windows where it calls SwitchToThread. It does nothing on other operating systems.