From 56978d40a91938455a658827a34ea8ddedfaff4e Mon Sep 17 00:00:00 2001 From: zhangxuetong Date: Wed, 9 Dec 2020 17:18:06 +0800 Subject: [PATCH] fix thread pool bug --- mindspore/lite/src/runtime/thread_pool.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mindspore/lite/src/runtime/thread_pool.c b/mindspore/lite/src/runtime/thread_pool.c index bbaa3ae579..8fa49aa5f4 100644 --- a/mindspore/lite/src/runtime/thread_pool.c +++ b/mindspore/lite/src/runtime/thread_pool.c @@ -625,7 +625,7 @@ bool PopTaskFromQueue(Thread *thread, Task **task) { LOG_ERROR("thread is nullptr"); return false; } - if (thread->task_size == 0) { + if (atomic_load_explicit(&thread->task_size, memory_order_relaxed) == 0) { return false; } const int head_index = atomic_load_explicit(&thread->head, memory_order_relaxed); @@ -651,7 +651,7 @@ void WaitAllThread(struct ThreadPool *thread_pool) { LOG_ERROR("get thread failed, thread_id: %d", i); return; } - if (thread->task_size != 0) { + if (atomic_load_explicit(&thread->task_size, memory_order_acquire) != 0) { k_success_flag = false; break; } @@ -731,7 +731,7 @@ void ThreadRun(Thread *thread) { return; } task->func(task->content, thread_id); - atomic_fetch_sub_explicit(&thread->task_size, 1, memory_order_relaxed); + atomic_fetch_sub_explicit(&thread->task_size, 1, memory_order_release); spin_count = 0; sem_trywait(&thread->sem); } else {