mxnet
Public Types | Public Member Functions | Static Public Member Functions | List of all members
dmlc::ThreadGroup::Thread Class Reference

Lifecycle-managed thread (used by ThreadGroup) More...

#include <thread_group.h>

Inheritance diagram for dmlc::ThreadGroup::Thread:
Inheritance graph
Collaboration diagram for dmlc::ThreadGroup::Thread:
Collaboration graph

Public Types

using SharedPtr = std::shared_ptr< Thread >
 Shared pointer type for readability. More...
 

Public Member Functions

 Thread (std::string threadName, ThreadGroup *owner, std::thread *thrd=nullptr)
 Constructor. More...
 
virtual ~Thread ()
 Destructor with cleanup. More...
 
const char * name () const
 Name of the thread. More...
 
bool is_current_thread () const
 Check if this class represents the currently running thread (self) More...
 
virtual void request_shutdown ()
 Signal to this thread that a thread shutdown/exit is requested. More...
 
virtual bool is_shutdown_requested () const
 Check whether shutdown has been requested (request_shutdown() was called) More...
 
bool is_auto_remove () const
 Check whether the thread is set to auto-remove itself from the ThreadGroup owner when exiting. More...
 
void make_joinable ()
 Make the thread joinable (by removing the auto_remove flag) More...
 
bool joinable () const
 Check whether the thread is joinable. More...
 
void join ()
 Thread join. More...
 
std::thread::id get_id () const
 Get this thread's id. More...
 

Static Public Member Functions

template<typename StartFunction , typename... Args>
static bool launch (std::shared_ptr< Thread > pThis, bool autoRemove, StartFunction start_function, Args...args)
 Launch the given Thread object. More...
 

Detailed Description

Lifecycle-managed thread (used by ThreadGroup)

Note
See gtest unit tests Syc.* for a usage examples

Member Typedef Documentation

using dmlc::ThreadGroup::Thread::SharedPtr = std::shared_ptr<Thread>

Shared pointer type for readability.

Constructor & Destructor Documentation

dmlc::ThreadGroup::Thread::Thread ( std::string  threadName,
ThreadGroup owner,
std::thread *  thrd = nullptr 
)
inline

Constructor.

Parameters
threadNameUser-defined name of the thread. must be unique per ThreadGroup
ownerThe ThreadGroup object managing the lifecycle of this thread
thrdOptionally-assigned std::thread object associated with this Thread class
virtual dmlc::ThreadGroup::Thread::~Thread ( )
inlinevirtual

Destructor with cleanup.

Member Function Documentation

std::thread::id dmlc::ThreadGroup::Thread::get_id ( ) const
inline

Get this thread's id.

Returns
this thread's id
bool dmlc::ThreadGroup::Thread::is_auto_remove ( ) const
inline

Check whether the thread is set to auto-remove itself from the ThreadGroup owner when exiting.

Returns
true if the thread will auto-remove itself from the ThreadGroup owner when exiting
bool dmlc::ThreadGroup::Thread::is_current_thread ( ) const
inline

Check if this class represents the currently running thread (self)

Returns
true if the current running thread belongs to this class
virtual bool dmlc::ThreadGroup::Thread::is_shutdown_requested ( ) const
inlinevirtual

Check whether shutdown has been requested (request_shutdown() was called)

Returns
true if shutdown was requested.
Note
This may be overriden to match an overriden to match an overriden 'request_shutdown()', for instance.
void dmlc::ThreadGroup::Thread::join ( )
inline

Thread join.

Note
join() may not be called on auto-remove threads
bool dmlc::ThreadGroup::Thread::joinable ( ) const
inline

Check whether the thread is joinable.

Returns
true if the thread is joinable
template<typename StartFunction , typename... Args>
bool dmlc::ThreadGroup::Thread::launch ( std::shared_ptr< Thread pThis,
bool  autoRemove,
StartFunction  start_function,
Args...  args 
)
inlinestatic

Launch the given Thread object.

Template Parameters
StartFunctionFunction type for the thread 'main' function
ArgsArguments to pass to the thread 'main' function
Parameters
pThisShared pointer for the managed thread to launch
autoRemoveif true, automatically remove this Thread object from the ThreadGroup owner upon exit
start_functionThe Thread's 'main' function
argsArguments to pass to the Thread's 'main' function
Returns
true if the thread was successfully created and added to the ThreadGroup If false is returned, the thread may have already been started, but if something went wrong (ie duplicte thread name for the ThreadGroup), then request_shutdown() will have been been called on the running thread
void dmlc::ThreadGroup::Thread::make_joinable ( )
inline

Make the thread joinable (by removing the auto_remove flag)

Warning
Care should be taken not to cause a race condition between this call and parallel execution of this thread auto-removing itself
const char* dmlc::ThreadGroup::Thread::name ( ) const
inline

Name of the thread.

Returns
Pointer to the thread name's string
Note
This shoul ndly be used as immediate for the sacope of the shared pointer pointing to this object
virtual void dmlc::ThreadGroup::Thread::request_shutdown ( )
inlinevirtual

Signal to this thread that a thread shutdown/exit is requested.

Note
This is a candidate for overrise in a derived class which may trigger shutdown by means other than a boolean (ie condition variable, SimpleManualkEvent, etc).

Reimplemented in dmlc::BlockingQueueThread< ObjectType, quit_item >.


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