Lifecycle-managed thread (used by ThreadGroup)
More...
#include <thread_group.h>
|
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...
|
|
Lifecycle-managed thread (used by ThreadGroup)
- Note
- See gtest unit tests Syc.* for a usage examples
Shared pointer type for readability.
dmlc::ThreadGroup::Thread::Thread |
( |
std::string |
threadName, |
|
|
ThreadGroup * |
owner, |
|
|
std::thread * |
thrd = nullptr |
|
) |
| |
|
inline |
Constructor.
- Parameters
-
threadName | User-defined name of the thread. must be unique per ThreadGroup |
owner | The ThreadGroup object managing the lifecycle of this thread |
thrd | Optionally-assigned std::thread object associated with this Thread class |
virtual dmlc::ThreadGroup::Thread::~Thread |
( |
| ) |
|
|
inlinevirtual |
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
-
StartFunction | Function type for the thread 'main' function |
Args | Arguments to pass to the thread 'main' function |
- Parameters
-
pThis | Shared pointer for the managed thread to launch |
autoRemove | if true, automatically remove this Thread object from the ThreadGroup owner upon exit |
start_function | The Thread's 'main' function |
args | Arguments 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: