diff --git a/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h b/src/UtilsCtrl/ThreadPool/Semaphore/USemaphore.h index 3c53ba01..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_--; - if (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_; };