Thread
Functions
SET_CID |
|
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 |
void | ChangeToAnotherThread |
Detailed Description
-
class
Thread
: public RED::Object Encapsulation of threading services.
@related Backbone
- Call RED::Thread::Setup to define a thread’s callback,
- Call RED::Thread::Run to start a thread,
- The threaded method receives the RED::Thread class itself as its argument, then RED::Thread::GetUserArgument can be used to access the RED::Thread::Setup method’s argument.
- Call RED::Thread::StopRun from the threaded method to end the thread,
- Call RED::Thread::WaitForTermination to wait for a thread’s end from the thread launcher.
- Call RED::Thread::Close after the WaitForTermination call to close the thread.
Public Functions
-
SET_CID (CID_class_REDThread) IMPLEMENT_AS()
-
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.
Public Static Functions
-
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.