Patch ppqsort to fix binary_semaphore release race.

This commit is contained in:
Bartosz Taudul
2026-05-04 01:13:25 +02:00
parent 04728994a5
commit 5bbafeabd7
2 changed files with 15 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
diff --git i/include/ppqsort/parallel/cpp/thread_pool.h w/include/ppqsort/parallel/cpp/thread_pool.h
--- i/include/ppqsort/parallel/cpp/thread_pool.h
+++ w/include/ppqsort/parallel/cpp/thread_pool.h
@@ -134,7 +134,9 @@ namespace ppqsort::impl::cpp {
alignas(parameters::cacheline_size) std::atomic<std::size_t> pending_tasks_{0};
alignas(parameters::cacheline_size) std::atomic<std::size_t> total_tasks_{0};
alignas(parameters::cacheline_size) std::atomic<bool> to_stop_{false};
- std::binary_semaphore threads_done_semaphore_{0}; // used to wait for all tasks to finish
+ // counting_semaphore: multiple workers may concurrently observe total_tasks_ == 0
+ // and call release(); a binary_semaphore would assert when the count exceeds 1.
+ std::counting_semaphore<> threads_done_semaphore_{0};
std::mutex mtx_priority_;
bool stopped = false;
};

View File

@@ -199,6 +199,7 @@ CPMAddPackage(
VERSION 1.0.6
PATCHES
"${CMAKE_CURRENT_LIST_DIR}/ppqsort-nodebug.patch"
"${CMAKE_CURRENT_LIST_DIR}/ppqsort-semaphore.patch"
EXCLUDE_FROM_ALL TRUE
)