AGX Dynamics 2.40.1.1
Loading...
Searching...
No Matches
agx::BasicThread Class Reference

Basic wrapper class aroud std::thread. More...

#include <Thread.h>

+ Inheritance diagram for agx::BasicThread:

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.
 
BasicThreadoperator= (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
 

Detailed Description

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.

Definition at line 83 of file Thread.h.

Member Enumeration Documentation

◆ ThreadState

States for the thread.

Enumerator
THREAD_NEW 
THREAD_RUNNING 
THREAD_DETACHED 
THREAD_DONE 
THREAD_JOINED 
THREAD_CANCELLED 

Definition at line 90 of file Thread.h.

Constructor & Destructor Documentation

◆ BasicThread() [1/2]

agx::BasicThread::BasicThread ( )

Default constructor.

◆ BasicThread() [2/2]

agx::BasicThread::BasicThread ( const BasicThread other)
delete

◆ ~BasicThread()

virtual agx::BasicThread::~BasicThread ( )
virtualdefault

Destructor.

Member Function Documentation

◆ cancel()

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.

◆ detach()

void agx::BasicThread::detach ( )

Detaches the thread to the background.

Will no longer be joinable.

◆ getCurrentThreadHandle()

static std::thread::native_handle_type agx::BasicThread::getCurrentThreadHandle ( )
static

Return a native_handle for the current executing thread.

◆ getThreadState()

unsigned int agx::BasicThread::getThreadState ( )
inline

Returns the current thread state.

Definition at line 641 of file Thread.h.

References m_state.

◆ join()

bool agx::BasicThread::join ( )

Joins the thread.

Will block until the thread is done executing.

◆ joinable()

bool agx::BasicThread::joinable ( )
inline

True if thread is joinable.

Definition at line 634 of file Thread.h.

References m_handle.

◆ operator=()

BasicThread & agx::BasicThread::operator= ( const BasicThread rhs)
delete

◆ run()

virtual void agx::BasicThread::run ( )
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.

Definition at line 117 of file Thread.h.

◆ setThreadAffinity()

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.

◆ start()

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.

Member Data Documentation

◆ m_handle

std::thread agx::BasicThread::m_handle
protected

Definition at line 187 of file Thread.h.

Referenced by joinable().

◆ m_state

std::atomic< unsigned int> agx::BasicThread::m_state
protected

Definition at line 188 of file Thread.h.

Referenced by getThreadState().


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