Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,12 @@ CStatus UThreadPool::releaseSecondaryThread(CInt size) {
CIndex UThreadPool::dispatch(const CIndex origIndex) {
CIndex realIndex = 0;
if (CGRAPH_DEFAULT_TASK_STRATEGY == origIndex) {
realIndex = cur_index_++;
realIndex = cur_index_.fetch_add(1, std::memory_order_relaxed) % config_.max_thread_size_;
if (realIndex >= 0 && realIndex < config_.default_thread_size_
&& primary_threads_[realIndex]->is_running_) {
// 如果是默认调度,并且被放置到 正在running 的pt中,则切换为 trigger_one 的策略,防止阻塞
realIndex = CGRAPH_TRIGGER_ALL_THREAD_STRATEGY;
}

if (cur_index_ >= config_.max_thread_size_ || cur_index_ < 0) {
cur_index_ = 0;
}
} else {
realIndex = origIndex;
}
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/UThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class UThreadPool : public UThreadObject {

private:
CBool is_init_ { false }; // 是否初始化
CInt cur_index_ = 0; // 记录放入的线程数
std::atomic<CInt> cur_index_ { 0 }; // 记录放入的线程数
UAtomicQueue<UTask> task_queue_; // 用于存放普通任务
UAtomicPriorityQueue<UTask> priority_task_queue_; // 运行时间较长的任务队列,仅在辅助线程中执行
std::vector<UThreadPrimaryPtr> primary_threads_; // 记录所有的主线程
Expand Down
2 changes: 1 addition & 1 deletion test/Performance/test-performance-04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void test_performance_04() {

const int layer = 8;
const int nodePerLayer = 8;
const int runTimes = 100000;
const int runTimes = 300000;

UThreadPoolConfig config;
config.default_thread_size_ = nodePerLayer;
Expand Down
2 changes: 1 addition & 1 deletion tutorial/T01-Simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void tutorial_simple() {

/* 运行流图信息。初始化后,支持多次循环计算 */
for (int i = 0; i < 3; i++) {
status += pipeline->run();
status = pipeline->run();
CGRAPH_ECHO("==== tutorial_simple, loop : [%d], and run status = [%d].", i + 1, status.getCode());
}

Expand Down
Loading