You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for (int i = 0; i < multi_queue_num_threads - 1; ++i) {
220
220
this->sub_threads_[i] = std::thread(&ParallelConnectionRouter::timing_driven_find_single_shortest_path_from_heap_sub_thread_wrapper, this, i + 1/*0: main thread*/);
221
-
this->sub_threads_[i].detach();
222
221
}
223
222
}
224
223
225
224
~ParallelConnectionRouter() {
226
225
this->is_router_destroying_ = true; // signal the helper threads to exit
227
226
this->thread_barrier_.wait(); // wait until all threads reach the barrier
227
+
for (auto& sub_thread : this->sub_threads_) {
228
+
VTR_ASSERT(sub_thread.joinable());
229
+
// Wait for all helper threads to terminate
230
+
//
231
+
// IMPORTANT: This must be done before the main thread destructs this object,
232
+
// otherwise, helper threads might have access to polluted data members, leading
233
+
// to undefined behavior. In some cases, due to timing issues between threads,
234
+
// for example, after both main and helper threads hit the barrier, the main
235
+
// thread completes object destruction/cleanup before helper threads can check
236
+
// `this->is_router_destroying_ == true` in `..._sub_thread_wrapper` function,
237
+
// helper threads may still see `this->is_router_destroying_` as false and fail
238
+
// to exit their thread functions. This results in helper threads remaining alive
239
+
// and accessing invalid memory addresses, leading to segfaults (please refer to
240
+
// https://github.com/verilog-to-routing/vtr-verilog-to-routing/issues/3029 for
241
+
// details).
242
+
sub_thread.join();
243
+
}
228
244
229
245
VTR_LOG("Parallel Connection Router is being destroyed. Time spent on path search: %.3f seconds.\n",
230
246
std::chrono::duration<float/*convert to seconds by default*/>(this->path_search_cumulative_time).count());
0 commit comments