Skip to content

Commit

Permalink
bugfix: 修复了添加辅助线程后,可能出现的唤醒休眠问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Oct 21, 2024
1 parent 531b130 commit 3a6022a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ message("* | |____ | | | | *")
message("* \\_____| |_| |_| *")
message("* * * * * * * * * * * * * * * * *")

cmake_minimum_required(VERSION 3.2.5)
cmake_minimum_required(VERSION 3.5.0)

project(CThreadPool VERSION 1.2.1)

Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class UThreadSecondary : public UThreadBase {
if (popPoolTask(task)) {
runTask(task);
} else {
// 如果单词无法获取,则稍加等待
// 如果单次无法获取,则稍加等待
waitRunTask(config_->queue_emtpy_interval_);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,8 @@ CStatus UThreadPool::releaseSecondaryThread(CInt size) {
CIndex UThreadPool::dispatch(CIndex origIndex) {
CIndex realIndex = 0;
if (CGRAPH_DEFAULT_TASK_STRATEGY == origIndex) {
/**
* 如果是默认策略信息,在[0, default_thread_size_) 之间的,通过 thread 中queue来调度
* 在[default_thread_size_, max_thread_size_) 之间的,通过 pool 中的queue来调度
*/
realIndex = cur_index_++;
if (cur_index_ >= config_.max_thread_size_ || cur_index_ < 0) {
if (cur_index_ >= config_.default_thread_size_ || cur_index_ < 0) {
cur_index_ = 0;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ static const int CGRAPH_LONG_TIME_TASK_STRATEGY = -101;
static const int CGRAPH_DEFAULT_THREAD_SIZE = 8; // 默认开启主线程个数
static const int CGRAPH_SECONDARY_THREAD_SIZE = 0; // 默认开启辅助线程个数
static const int CGRAPH_MAX_THREAD_SIZE = 16; // 最大线程个数
static const int CGRAPH_MAX_TASK_STEAL_RANGE = 2; // 盗取机制相邻范围
static const int CGRAPH_MAX_TASK_STEAL_RANGE = 7; // 盗取机制相邻范围
static const bool CGRAPH_BATCH_TASK_ENABLE = false; // 是否开启批量任务功能
static const int CGRAPH_MAX_LOCAL_BATCH_SIZE = 2; // 批量执行本地任务最大值
static const int CGRAPH_MAX_POOL_BATCH_SIZE = 2; // 批量执行通用任务最大值
static const int CGRAPH_MAX_STEAL_BATCH_SIZE = 2; // 批量盗取任务最大值
static const int CGRAPH_PRIMARY_THREAD_BUSY_EPOCH = 10; // 主线程进入wait状态的轮数,数值越大,理论性能越高,但空转可能性也越大
static const CMSec CGRAPH_PRIMARY_THREAD_EMPTY_INTERVAL = 3; // 主线程进入休眠状态的默认时间
static const CMSec CGRAPH_PRIMARY_THREAD_EMPTY_INTERVAL = 1000; // 主线程进入休眠状态的默认时间
static const int CGRAPH_SECONDARY_THREAD_TTL = 10; // 辅助线程ttl,单位为s
static const bool CGRAPH_MONITOR_ENABLE = false; // 是否开启监控程序
static const CSec CGRAPH_MONITOR_SPAN = 5; // 监控线程执行间隔,单位为s
Expand Down

0 comments on commit 3a6022a

Please sign in to comment.