Open CASCADE Technology  7.2.0
Public Member Functions | Static Public Member Functions
OSD_Thread Class Reference

A simple platform-intependent interface to execute and control threads. More...

#include <OSD_Thread.hxx>

Public Member Functions

 OSD_Thread ()
 Empty constructor. More...
 
 OSD_Thread (const OSD_ThreadFunction &func)
 Initialize the tool by the thread function. More...
 
 OSD_Thread (const OSD_Thread &other)
 Copy constructor. More...
 
void Assign (const OSD_Thread &other)
 Copy thread handle from other OSD_Thread object. More...
 
void operator= (const OSD_Thread &other)
 
 ~OSD_Thread ()
 Destructor. Detaches the thread if it wasn't done already. More...
 
void SetPriority (const Standard_Integer thePriority)
 
void SetFunction (const OSD_ThreadFunction &func)
 Initialize the tool by the thread function. If the current thread handle is not null, nullifies it. More...
 
Standard_Boolean Run (const Standard_Address data=0, const Standard_Integer WNTStackSize=0)
 Starts a thread with thread function given in constructor, passing the specified input data (as void *) to it. The parameter WNTStackSize (on Windows only) specifies size of the stack to be allocated for the thread (by default - the same as for the current executable). Returns True if thread started successfully. More...
 
void Detach ()
 Detaches the execution thread from this Thread object, so that it cannot be waited. Note that mechanics of this operation is different on UNIX/Linux (the thread is put to detached state) and Windows (the handle is closed). However, the purpose is the same: to instruct the system to release all thread data upon its completion. More...
 
Standard_Boolean Wait ()
 Waits till the thread finishes execution. More...
 
Standard_Boolean Wait (Standard_Address &theResult)
 Wait till the thread finishes execution. Returns True if wait was successful, False in case of error. More...
 
Standard_Boolean Wait (const Standard_Integer time, Standard_Address &theResult)
 Waits for some time and if the thread is finished, it returns the result. The function returns false if the thread is not finished yet. More...
 
Standard_ThreadId GetId () const
 Returns ID of the currently controlled thread ID, or 0 if no thread is run. More...
 

Static Public Member Functions

static Standard_ThreadId Current ()
 Auxiliary: returns ID of the current thread. More...
 

Detailed Description

A simple platform-intependent interface to execute and control threads.

Constructor & Destructor Documentation

◆ OSD_Thread() [1/3]

OSD_Thread::OSD_Thread ( )

Empty constructor.

◆ OSD_Thread() [2/3]

OSD_Thread::OSD_Thread ( const OSD_ThreadFunction func)

Initialize the tool by the thread function.

Note: On Windows, you might have to take an address of the thread function explicitly to pass it to this constructor without compiler error

◆ OSD_Thread() [3/3]

OSD_Thread::OSD_Thread ( const OSD_Thread other)

Copy constructor.

◆ ~OSD_Thread()

OSD_Thread::~OSD_Thread ( )

Destructor. Detaches the thread if it wasn't done already.

Member Function Documentation

◆ Assign()

void OSD_Thread::Assign ( const OSD_Thread other)

Copy thread handle from other OSD_Thread object.

◆ Current()

static Standard_ThreadId OSD_Thread::Current ( )
static

Auxiliary: returns ID of the current thread.

◆ Detach()

void OSD_Thread::Detach ( )

Detaches the execution thread from this Thread object, so that it cannot be waited. Note that mechanics of this operation is different on UNIX/Linux (the thread is put to detached state) and Windows (the handle is closed). However, the purpose is the same: to instruct the system to release all thread data upon its completion.

◆ GetId()

Standard_ThreadId OSD_Thread::GetId ( ) const

Returns ID of the currently controlled thread ID, or 0 if no thread is run.

◆ operator=()

void OSD_Thread::operator= ( const OSD_Thread other)
inline

◆ Run()

Standard_Boolean OSD_Thread::Run ( const Standard_Address  data = 0,
const Standard_Integer  WNTStackSize = 0 
)

Starts a thread with thread function given in constructor, passing the specified input data (as void *) to it. The parameter WNTStackSize (on Windows only) specifies size of the stack to be allocated for the thread (by default - the same as for the current executable). Returns True if thread started successfully.

◆ SetFunction()

void OSD_Thread::SetFunction ( const OSD_ThreadFunction func)

Initialize the tool by the thread function. If the current thread handle is not null, nullifies it.

Note: On Windows, you might have to take an address of the thread function explicitly to pass it to this method without compiler error

◆ SetPriority()

void OSD_Thread::SetPriority ( const Standard_Integer  thePriority)

◆ Wait() [1/3]

Standard_Boolean OSD_Thread::Wait ( )
inline

Waits till the thread finishes execution.

◆ Wait() [2/3]

Standard_Boolean OSD_Thread::Wait ( Standard_Address theResult)

Wait till the thread finishes execution. Returns True if wait was successful, False in case of error.

If successful and result argument is provided, saves the pointer (void*) returned by the thread function in result.

Note however that it is advisable not to rely upon returned result value, as it is not always the value actually returned by the thread function. In addition, on Windows it is converted via DWORD.

◆ Wait() [3/3]

Standard_Boolean OSD_Thread::Wait ( const Standard_Integer  time,
Standard_Address theResult 
)

Waits for some time and if the thread is finished, it returns the result. The function returns false if the thread is not finished yet.


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