![]() |
AGX Dynamics 2.40.1.1
|
Basic wrapper class aroud std::thread. More...
#include <Thread.h>
Public Types | |
enum | ThreadState { THREAD_NEW = 0 , THREAD_RUNNING = 1 , THREAD_DETACHED = 2 , THREAD_DONE = 3 , THREAD_JOINED = 4 , THREAD_CANCELLED = 5 } |
States for the thread. More... | |
Public Member Functions | |
BasicThread () | |
Default constructor. | |
BasicThread (const BasicThread &other)=delete | |
virtual | ~BasicThread ()=default |
Destructor. | |
void | cancel () |
Threads should normally not need to be killed. | |
void | detach () |
Detaches the thread to the background. | |
unsigned int | getThreadState () |
Returns the current thread state. | |
bool | join () |
Joins the thread. | |
bool | joinable () |
True if thread is joinable. | |
BasicThread & | operator= (const BasicThread &rhs)=delete |
virtual void | run () |
This method is invoked by start. | |
bool | setThreadAffinity (agx::UInt64 cpumask) |
Thread Affinity can be used to influence on which logical cores threads are scheduled and allowed to run. | |
bool | start () |
Launches the thread. | |
Static Public Member Functions | |
static std::thread::native_handle_type | getCurrentThreadHandle () |
Return a native_handle for the current executing thread. | |
Protected Attributes | |
std::thread | m_handle |
std::atomic< unsigned int > | m_state |
Basic wrapper class aroud std::thread.
The work will be done in the run method.
All threads that are started should either be joined or detached.
agx::BasicThread::BasicThread | ( | ) |
Default constructor.
|
delete |
|
virtualdefault |
Destructor.
void agx::BasicThread::cancel | ( | ) |
Threads should normally not need to be killed.
Killing a thread can have bad consequences and leak resources. This will forcefully terminate the thread.
The thread should still be joined even after cancel has been called.
void agx::BasicThread::detach | ( | ) |
Detaches the thread to the background.
Will no longer be joinable.
|
static |
Return a native_handle for the current executing thread.
|
inline |
bool agx::BasicThread::join | ( | ) |
Joins the thread.
Will block until the thread is done executing.
|
inline |
|
delete |
|
inlinevirtual |
This method is invoked by start.
Override in child classes to perform the work.
Reimplemented in agxNet::CoSimulationServer, agxNet::RemoteDebugBase, and agxOSG::ImageCaptureBase::WriteImageThread.
bool agx::BasicThread::setThreadAffinity | ( | agx::UInt64 | cpumask | ) |
Thread Affinity can be used to influence on which logical cores threads are scheduled and allowed to run.
On Windows and Linux, the input is a bitmask where the bits that are set are maps to logical cores.
On OS X, the input value is an affinity tag and threads with the same tag are scheduled so they should share and L2 cache.
Note: If the BasicThread has not yet been launched via start(), then this method will affect the current executing thread.
bool agx::BasicThread::start | ( | ) |
Launches the thread.
Will execute the run method. If a thread is already started and we have a joinable handle, start will not launch another thread and instead return false.
Returns true on success.
|
protected |
Definition at line 187 of file Thread.h.
Referenced by joinable().
|
protected |
Definition at line 188 of file Thread.h.
Referenced by getThreadState().