Skip to content

Commit 7933a6c

Browse files
Merge pull request #3094 from ueqri/fixed-parallel-connection-router-segfault-bug
[Router] Fixed the Segfault Bug in Parallel Connection Router
2 parents 7865234 + 50712fe commit 7933a6c

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

vpr/src/route/parallel_connection_router.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,29 @@ class ParallelConnectionRouter : public ConnectionRouter<MultiQueueDAryHeap<Heap
218218
this->sub_threads_.resize(multi_queue_num_threads - 1);
219219
for (int i = 0; i < multi_queue_num_threads - 1; ++i) {
220220
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();
222221
}
223222
}
224223

225224
~ParallelConnectionRouter() {
226225
this->is_router_destroying_ = true; // signal the helper threads to exit
227226
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+
}
228244

229245
VTR_LOG("Parallel Connection Router is being destroyed. Time spent on path search: %.3f seconds.\n",
230246
std::chrono::duration<float /*convert to seconds by default*/>(this->path_search_cumulative_time).count());

vtr_flow/tasks/regression_tests/vtr_reg_strong/strong_multiclock/config/config.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ script_params_common=-starting_stage vpr -sdc_file tasks/regression_tests/vtr_re
2828
script_params_list_add =
2929
script_params_list_add = --route_chan_width 30 -check_incremental_sta_consistency
3030
script_params_list_add = --router_algorithm parallel --num_workers 4
31-
# script_params_list_add = --enable_parallel_connection_router on --astar_fac 0.0 --post_target_prune_fac 0.0 --post_target_prune_offset 0.0
32-
# script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --astar_fac 0.0 --post_target_prune_fac 0.0 --post_target_prune_offset 0.0
33-
# script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 8 --multi_queue_direct_draining on --astar_fac 0.0 --post_target_prune_fac 0.0 --post_target_prune_offset 0.0
31+
script_params_list_add = --enable_parallel_connection_router on --astar_fac 0.0 --post_target_prune_fac 0.0 --post_target_prune_offset 0.0
32+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 4 --astar_fac 0.0 --post_target_prune_fac 0.0 --post_target_prune_offset 0.0
33+
script_params_list_add = --enable_parallel_connection_router on --multi_queue_num_threads 2 --multi_queue_num_queues 8 --multi_queue_direct_draining on --astar_fac 0.0 --post_target_prune_fac 0.0 --post_target_prune_offset 0.0

vtr_flow/tasks/regression_tests/vtr_reg_strong/strong_multiclock/config/golden_results.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
k6_frac_N10_mem32K_40nm.xml multiclock.blif common 1.59919 0.595 0.841581 -1 -1 0.57 0.814813 -1 1.59919 -1 1.1662 -1 1.8371 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.243 1.71958 -1 -1 0.268 3.24281 -1 1.44782 -1 3.4042 -1 -1.40928 -1 -1 -1 -1
33
k6_frac_N10_mem32K_40nm.xml multiclock.blif common_--route_chan_width_30_-check_incremental_sta_consistency 1.3344 0.595 0.781297 -1 -1 0.57 0.757256 -1 1.3344 -1 1.16524 -1 1.77873 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.243 1.6593 -1 -1 0.268 3.18526 -1 1.18303 -1 3.40324 -1 -1.46764 -1 -1 -1 -1
44
k6_frac_N10_mem32K_40nm.xml multiclock.blif common_--router_algorithm_parallel_--num_workers_4 1.59919 0.595 0.841581 -1 -1 0.57 0.814813 -1 1.59919 -1 1.14847 -1 1.95678 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.243 1.71958 -1 -1 0.268 3.24281 -1 1.44782 -1 3.38647 -1 -1.28959 -1 -1 -1 -1
5+
k6_frac_N10_mem32K_40nm.xml multiclock.blif common_--enable_parallel_connection_router_on_--astar_fac_0.0_--post_target_prune_fac_0.0_--post_target_prune_offset_0.0 1.59919 0.595 0.841581 -1 -1 0.57 0.814813 -1 1.59919 -1 1.14847 -1 1.95678 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.243 1.71958 -1 -1 0.268 3.24281 -1 1.44782 -1 3.38647 -1 -1.28959 -1 -1 -1 -1
6+
k6_frac_N10_mem32K_40nm.xml multiclock.blif common_--enable_parallel_connection_router_on_--multi_queue_num_threads_2_--multi_queue_num_queues_4_--astar_fac_0.0_--post_target_prune_fac_0.0_--post_target_prune_offset_0.0 1.59919 0.595 0.841581 -1 -1 0.57 0.814813 -1 1.59919 -1 1.14847 -1 1.95678 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.243 1.71958 -1 -1 0.268 3.24281 -1 1.44782 -1 3.38647 -1 -1.28959 -1 -1 -1 -1
7+
k6_frac_N10_mem32K_40nm.xml multiclock.blif common_--enable_parallel_connection_router_on_--multi_queue_num_threads_2_--multi_queue_num_queues_8_--multi_queue_direct_draining_on_--astar_fac_0.0_--post_target_prune_fac_0.0_--post_target_prune_offset_0.0 1.59919 0.595 0.841581 -1 -1 0.57 0.814813 -1 1.59919 -1 1.14847 -1 1.95678 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.243 1.71958 -1 -1 0.268 3.24281 -1 1.44782 -1 3.38647 -1 -1.28959 -1 -1 -1 -1

0 commit comments

Comments
 (0)