MCPcopy Create free account
hub / github.com/dmlc/dmlc-core / Thread

Class Thread

include/dmlc/thread_group.h:101–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99 * \note See gtest unit tests Syc.* for a usage examples
100 */
101 class Thread {
102 public:
103 /*! \brief Shared pointer type for readability */
104 using SharedPtr = std::shared_ptr<Thread>;
105
106 /*!
107 * \brief Constructor
108 * \param threadName User-defined name of the thread. must be unique per ThreadGroup
109 * \param owner The ThreadGroup object managing the lifecycle of this thread
110 * \param thrd Optionally-assigned std::thread object associated with this Thread class
111 */
112 Thread(std::string threadName, ThreadGroup *owner, std::thread *thrd = nullptr)
113 : name_(std::move(threadName))
114 , thread_(thrd)
115 , ready_event_(std::make_shared<ManualEvent>())
116 , start_event_(std::make_shared<ManualEvent>())
117 , owner_(owner)
118 , shutdown_requested_(false)
119 , auto_remove_(false) {
120 CHECK_NOTNULL(owner);
121 }
122
123 /*!
124 * \brief Destructor with cleanup
125 */
126 virtual ~Thread() {
127 const bool self_delete = is_current_thread();
128 if (!self_delete) {
129 request_shutdown();
130 internal_join(true);
131 }
132 WriteLock guard(thread_mutex_);
133 if (thread_.load()) {
134 std::thread *thrd = thread_.load();
135 thread_ = nullptr;
136 if (self_delete) {
137 thrd->detach();
138 }
139 delete thrd;
140 }
141 }
142
143 /*!
144 * \brief Name of the thread
145 * \return Pointer to the thread name's string
146 * \note This shoul ndly be used as immediate for the sacope of the
147 * shared pointer pointing to this object
148 */
149 const char *name() const {
150 return name_.c_str();
151 }
152
153 /*!
154 * \brief Launch the given Thread object
155 * \tparam StartFunction Function type for the thread 'main' function
156 * \tparam Args Arguments to pass to the thread 'main' function
157 * \param pThis Shared pointer for the managed thread to launch
158 * \param autoRemove if true, automatically remove this Thread object from the

Callers 8

mthread_submitFunction · 0.85
mpi_submitFunction · 0.85
ssh_submitFunction · 0.85
mesos_submitFunction · 0.85
mpi_submitFunction · 0.85
startMethod · 0.85
__init__Method · 0.85
yarn_submitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected