From cabc0af64755b5253b8fbf6db408df636a992a3b Mon Sep 17 00:00:00 2001 From: yeshenyong <52573793+yeshenyong@users.noreply.github.com> Date: Thu, 26 Feb 2026 22:23:47 +0800 Subject: [PATCH 1/2] [bugfix] fix USemaphore fake notify error cnt (#582) --- src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h b/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h index 3c53ba01..3180bfdf 100644 --- a/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h +++ b/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h @@ -35,7 +35,7 @@ class USemaphore : public UThreadObject { CVoid wait() { CGRAPH_UNIQUE_LOCK lk(mutex_); cnt_--; - if (cnt_ < 0) { + while (cnt_ < 0) { cv_.wait(lk); } } From b2882efeca40d0400eb53614530b3e20ae3d8394 Mon Sep 17 00:00:00 2001 From: Chunel Date: Thu, 26 Feb 2026 22:27:45 +0800 Subject: [PATCH 2/2] [perf] change USemaphore cv.wait condition --- src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h b/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h index 3180bfdf..5247a9a0 100644 --- a/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h +++ b/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h @@ -35,13 +35,13 @@ class USemaphore : public UThreadObject { CVoid wait() { CGRAPH_UNIQUE_LOCK lk(mutex_); cnt_--; - while (cnt_ < 0) { - cv_.wait(lk); - } + cv_.wait(lk, [this] { + return cnt_ < 0; + }); } private: - CInt cnt_ = 0; // 记录当前的次数 + CInt cnt_ { 0 }; // 记录当前的次数 std::mutex mutex_; std::condition_variable cv_; };