Skip to content

Commit dd55c6d

Browse files
committed
Probably fixed the segfault bug in parallel connection router
1 parent a92b449 commit dd55c6d

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

.github/workflows/test.yml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,41 @@ env:
3434
MATRIX_EVAL: "CC=gcc-13 && CXX=g++-13"
3535

3636
jobs:
37-
Build:
38-
name: 'B: Building VtR'
39-
runs-on: ubuntu-24.04
40-
strategy:
41-
fail-fast: false
42-
matrix:
43-
include:
44-
- { build_type: 'release', verbose: '0' }
45-
- { build_type: 'debug', verbose: '0' }
46-
- { build_type: 'debug', verbose: '1' }
47-
steps:
37+
# Build:
38+
# name: 'B: Building VtR'
39+
# runs-on: ubuntu-24.04
40+
# strategy:
41+
# fail-fast: false
42+
# matrix:
43+
# include:
44+
# - { build_type: 'release', verbose: '0' }
45+
# - { build_type: 'debug', verbose: '0' }
46+
# - { build_type: 'debug', verbose: '1' }
47+
# steps:
4848

49-
- uses: actions/setup-python@v5
50-
with:
51-
python-version: 3.12.3
52-
- uses: actions/checkout@v4
53-
with:
54-
submodules: 'true'
49+
# - uses: actions/setup-python@v5
50+
# with:
51+
# python-version: 3.12.3
52+
# - uses: actions/checkout@v4
53+
# with:
54+
# submodules: 'true'
5555

56-
- name: Get number of CPU cores
57-
uses: SimenB/github-actions-cpu-cores@v2
58-
id: cpu-cores
56+
# - name: Get number of CPU cores
57+
# uses: SimenB/github-actions-cpu-cores@v2
58+
# id: cpu-cores
5959

60-
- name: Install dependencies
61-
run: ./.github/scripts/install_dependencies.sh
60+
# - name: Install dependencies
61+
# run: ./.github/scripts/install_dependencies.sh
6262

63-
- uses: hendrikmuhs/[email protected]
63+
# - uses: hendrikmuhs/[email protected]
6464

65-
- name: Test
66-
env:
67-
BUILD_TYPE: ${{ matrix.build_type }}
68-
NUM_PROC: ${{ steps.cpu-cores.outputs.count }}
69-
run: |
70-
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
71-
./.github/scripts/build.sh VERBOSE=${{ matrix.verbose }}
65+
# - name: Test
66+
# env:
67+
# BUILD_TYPE: ${{ matrix.build_type }}
68+
# NUM_PROC: ${{ steps.cpu-cores.outputs.count }}
69+
# run: |
70+
# export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
71+
# ./.github/scripts/build.sh VERBOSE=${{ matrix.verbose }}
7272

7373

7474
# Format:

vpr/src/route/parallel_connection_router.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,24 @@ 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+
if (sub_thread.joinable()) {
229+
// Wait for all helper threads to terminate
230+
// IMPORTANT: This must be done before the main thread destructs this class,
231+
// otherwise, the helper threads might have polluted data members (or other
232+
// undefined behaviors). In some cases (due to compiler optimizations, e.g.,
233+
// shuffling instructions), the helper thread will remain alive and can access
234+
// invalid address leading to segmentation fault issues (for details refer to
235+
// https://github.com/verilog-to-routing/vtr-verilog-to-routing/issues/3029).
236+
sub_thread.join();
237+
}
238+
}
228239

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

0 commit comments

Comments
 (0)