diff --git a/src/UtilsCtrl/ThreadPool/Thread/UThreadBase.h b/src/UtilsCtrl/ThreadPool/Thread/UThreadBase.h index c0350385..70a6834d 100644 --- a/src/UtilsCtrl/ThreadPool/Thread/UThreadBase.h +++ b/src/UtilsCtrl/ThreadPool/Thread/UThreadBase.h @@ -241,7 +241,7 @@ class UThreadBase : public UThreadObject { protected: CBool done_; // 线程状态标记 CBool is_init_; // 标记初始化状态 - std::atomic is_running_; // 是否正在执行 + std::atomic is_running_ { false }; // 是否正在执行 CInt type_ = 0; // 用于区分线程类型(主线程、辅助线程) CULong total_task_num_ = 0; // 处理的任务的数字 diff --git a/src/UtilsCtrl/ThreadPool/UThreadPool.cpp b/src/UtilsCtrl/ThreadPool/UThreadPool.cpp index 6e497d8f..c062170e 100644 --- a/src/UtilsCtrl/ThreadPool/UThreadPool.cpp +++ b/src/UtilsCtrl/ThreadPool/UThreadPool.cpp @@ -295,19 +295,17 @@ CVoid UThreadPool::monitor() { CSize UThreadPool::wakeupAllThread() { CSize size = 0; - if (wakeup_mutex_.try_lock()) { - for (auto* pt : primary_threads_) { - if (pt->wakeup()) { - ++size; - } + CGRAPH_LOCK_GUARD lock(wakeup_mutex_); + for (auto* pt : primary_threads_) { + if (pt->wakeup()) { + ++size; } + } - for (const auto& st : secondary_threads_) { - if (st->wakeup()) { - ++size; - } + for (const auto& st : secondary_threads_) { + if (st->wakeup()) { + ++size; } - wakeup_mutex_.unlock(); } return size;