From 5bbafeabd7c38bcf7c264769a48e973173fd0430 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 4 May 2026 01:13:25 +0200 Subject: [PATCH] Patch ppqsort to fix binary_semaphore release race. --- cmake/ppqsort-semaphore.patch | 14 ++++++++++++++ cmake/vendor.cmake | 1 + 2 files changed, 15 insertions(+) create mode 100644 cmake/ppqsort-semaphore.patch diff --git a/cmake/ppqsort-semaphore.patch b/cmake/ppqsort-semaphore.patch new file mode 100644 index 00000000..911f7bc8 --- /dev/null +++ b/cmake/ppqsort-semaphore.patch @@ -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 pending_tasks_{0}; + alignas(parameters::cacheline_size) std::atomic total_tasks_{0}; + alignas(parameters::cacheline_size) std::atomic 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; + }; diff --git a/cmake/vendor.cmake b/cmake/vendor.cmake index 8a8a97d8..593cf37a 100644 --- a/cmake/vendor.cmake +++ b/cmake/vendor.cmake @@ -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 )