MCPcopy Create free account
hub / github.com/NVIDIA/DALI / ThreadMain

Method ThreadMain

dali/pipeline/util/worker_thread.cc:138–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138void WorkerThreadImpl::ThreadMain(int device_id, bool set_affinity, const std::string &name) {
139 SetThreadName(name.c_str());
140 DeviceGuard g(device_id);
141 try {
142 if (set_affinity) {
143#if NVML_ENABLED
144 nvml::SetCPUAffinity();
145#endif
146 }
147 } catch (std::exception &e) {
148 std::lock_guard<std::mutex> lock(mutex_);
149 errors_.push(e.what());
150 running_ = false;
151 } catch (...) {
152 std::lock_guard<std::mutex> lock(mutex_);
153 errors_.push("Unknown exception");
154 running_ = false;
155 }
156
157 barrier_.Wait();
158
159 while (running_) {
160 // Check the queue for work
161 std::unique_lock<std::mutex> lock(mutex_);
162 while (work_queue_.empty() && running_) {
163 cv_.wait(lock);
164 }
165
166 if (!running_) {
167 break;
168 }
169
170 Work work = std::move(work_queue_.front());
171 work_queue_.pop();
172 lock.unlock();
173
174 try {
175 work();
176 } catch (std::exception &e) {
177 std::cerr << std::this_thread::get_id() << " Exception in thread: " << e.what() << endl;
178 lock.lock();
179 errors_.push(e.what());
180 running_ = false;
181 completed_.notify_one();
182 lock.unlock();
183 break;
184 } catch (...) {
185 std::cerr << std::this_thread::get_id() << " Exception in thread" << endl;
186 lock.lock();
187 errors_.push("Caught unknown exception in thread.");
188 running_ = false;
189 completed_.notify_one();
190 lock.unlock();
191 break;
192 }
193
194 lock.lock();
195

Callers

nothing calls this directly

Calls 12

SetThreadNameFunction · 0.85
SetCPUAffinityFunction · 0.85
pushMethod · 0.80
c_strMethod · 0.45
whatMethod · 0.45
WaitMethod · 0.45
emptyMethod · 0.45
waitMethod · 0.45
frontMethod · 0.45
popMethod · 0.45
unlockMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected