mxnet
Classes | Public Member Functions | List of all members
dmlc::ThreadGroup Class Reference

Thread lifecycle management group. More...

#include <thread_group.h>

Collaboration diagram for dmlc::ThreadGroup:
Collaboration graph

Classes

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

Public Member Functions

 ThreadGroup ()
 Constructor. More...
 
virtual ~ThreadGroup ()
 Destructor, perform cleanup. All child threads will be exited when this destructor completes. More...
 
bool is_this_thread_in () const
 Check if the current thread a member if this ThreadGroup. More...
 
bool is_thread_in (std::shared_ptr< Thread > thrd) const
 Check if the current thread is a member of this ThreadGroup. More...
 
bool add_thread (std::shared_ptr< Thread > thrd)
 Add a Thread object to this thread group. More...
 
bool remove_thread (std::shared_ptr< Thread > thrd)
 Remove a Thread object from this thread group. More...
 
void join_all ()
 Join all threads in this ThreadGroup. More...
 
void request_shutdown_all (const bool make_all_joinable=true)
 Call request_shutdown() on all threads in this ThreadGroup. More...
 
size_t size () const
 Return the number of threads in this thread group. More...
 
bool empty () const
 Check if the ThreadGroup is empty. More...
 
template<typename StartFunction , typename ThreadType = Thread, typename... Args>
bool create (const std::string &threadName, bool auto_remove, StartFunction start_function, Args...args)
 Create and launch a new Thread object which will be owned by this ThreadGroup. More...
 
std::shared_ptr< Threadthread_by_name (const std::string &name)
 Lookup Thread object by name. More...
 

Detailed Description

Thread lifecycle management group.

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

Constructor & Destructor Documentation

dmlc::ThreadGroup::ThreadGroup ( )
inline

Constructor.

virtual dmlc::ThreadGroup::~ThreadGroup ( )
inlinevirtual

Destructor, perform cleanup. All child threads will be exited when this destructor completes.

Member Function Documentation

bool dmlc::ThreadGroup::add_thread ( std::shared_ptr< Thread thrd)
inline

Add a Thread object to this thread group.

Parameters
thrdThe thread to add to this ThreadGroup object
Returns
true if the given thread was added to this ThreadGroup
template<typename StartFunction , typename ThreadType = Thread, typename... Args>
bool dmlc::ThreadGroup::create ( const std::string &  threadName,
bool  auto_remove,
StartFunction  start_function,
Args...  args 
)
inline

Create and launch a new Thread object which will be owned by this ThreadGroup.

Template Parameters
StartFunctionFunction type for the thread 'main' function
ThreadTypemanagedThreadclass type (in case it's derived, for instance)
ArgsArguments to pass to the thread 'main' function
Parameters
threadNameName if the thread. Must be unique for a ThreadGroup object
auto_removeIf 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
bool dmlc::ThreadGroup::empty ( ) const
inline

Check if the ThreadGroup is empty.

Returns
true if the ThreadGroup is empty
bool dmlc::ThreadGroup::is_this_thread_in ( ) const
inline

Check if the current thread a member if this ThreadGroup.

Returns
true if the current thread is a member of this thread group
Note
This lookup involved a linear search, so for a large number of threads, is it not advised to call this function in a performance-sensitive area
bool dmlc::ThreadGroup::is_thread_in ( std::shared_ptr< Thread thrd) const
inline

Check if the current thread is a member of this ThreadGroup.

Parameters
thrdThe thread to search for
Returns
true if the given thread is a member of this ThreadGroup
void dmlc::ThreadGroup::join_all ( )
inline

Join all threads in this ThreadGroup.

Note
While it is not valid to call 'join' on an auto-remove thread, this function will wait for auto-remove threads to exit (waits for the ThreadGroup to become empty)
bool dmlc::ThreadGroup::remove_thread ( std::shared_ptr< Thread thrd)
inline

Remove a Thread object from this thread group.

Parameters
thrdThe thread to remove from this ThreadGroup object
Returns
true if the given thread was removed from this ThreadGroup
void dmlc::ThreadGroup::request_shutdown_all ( const bool  make_all_joinable = true)
inline

Call request_shutdown() on all threads in this ThreadGroup.

Parameters
make_all_joinableIf true, remove all auto_remove flags from child threads
size_t dmlc::ThreadGroup::size ( ) const
inline

Return the number of threads in this thread group.

Returns
Number of threads in this thread group
std::shared_ptr<Thread> dmlc::ThreadGroup::thread_by_name ( const std::string &  name)
inline

Lookup Thread object by name.

Parameters
nameName of the thread to look up
Returns
A shared pointer to the Thread object

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