From bbb4c8429f09d53207bcfd24c82848fe6d3311a5 Mon Sep 17 00:00:00 2001 From: Chunel Date: Mon, 23 Mar 2026 23:17:53 +0800 Subject: [PATCH] [bugfix] fix secondary thread leave waiting --- src/UtilsCtrl/ThreadPool/Queue/UAtomicQueue.h | 10 ++++++++-- src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/UtilsCtrl/ThreadPool/Queue/UAtomicQueue.h b/src/UtilsCtrl/ThreadPool/Queue/UAtomicQueue.h index 34cce6b2..bd06e1a9 100644 --- a/src/UtilsCtrl/ThreadPool/Queue/UAtomicQueue.h +++ b/src/UtilsCtrl/ThreadPool/Queue/UAtomicQueue.h @@ -145,7 +145,10 @@ class UAtomicQueue : public UQueueObject { * @return */ CVoid reset() { - ready_flag_ = false; + { + CGRAPH_UNIQUE_LOCK lk(mutex_); + ready_flag_ = false; + } cv_.notify_all(); } @@ -155,7 +158,10 @@ class UAtomicQueue : public UQueueObject { * @return */ CVoid setup() { - ready_flag_ = true; + { + CGRAPH_UNIQUE_LOCK lk(mutex_); + ready_flag_ = true; + } queue_ = {}; } diff --git a/src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h b/src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h index 4134ac27..c7c691f8 100644 --- a/src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h +++ b/src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h @@ -94,7 +94,7 @@ class UThreadSecondary : public UThreadBase { */ CVoid waitRunTask(const CMSec ms) { const auto& task = pool_task_queue_->popWithTimeout(ms); - if (nullptr != task) { + if (task) { runTask(*task); } }