From 704e454f1091ac355cebda09a1f23b6bfd24a99c Mon Sep 17 00:00:00 2001 From: liutiexing <74819124+liutiexing@users.noreply.github.com> Date: Thu, 28 Oct 2021 11:59:01 +0800 Subject: [PATCH] Fix cancel (#36740) * add align for WorkQueue * add spinlock * merge develop * merge * Add EventsWaiter * update * update * update Error MSG * update EventsWaiter * Add Cancel For ThreadPool * Add UT for Cancel * fix Cancel --- .../framework/new_executor/nonblocking_threadpool.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/framework/new_executor/nonblocking_threadpool.h b/paddle/fluid/framework/new_executor/nonblocking_threadpool.h index 6e56532456..cdcdbbb445 100644 --- a/paddle/fluid/framework/new_executor/nonblocking_threadpool.h +++ b/paddle/fluid/framework/new_executor/nonblocking_threadpool.h @@ -394,16 +394,16 @@ class ThreadPoolTempl { // We already did best-effort emptiness check in Steal, so prepare for // blocking. ec_.Prewait(); + if (cancelled_) { + ec_.CancelWait(); + return false; + } // Now do a reliable emptiness check. int victim = NonEmptyQueueIndex(); if (victim != -1) { ec_.CancelWait(); - if (cancelled_) { - return false; - } else { - *t = thread_data_[victim].queue.PopBack(); - return true; - } + *t = thread_data_[victim].queue.PopBack(); + return true; } // Number of blocked threads is used as termination condition. // If we are shutting down and all worker threads blocked without work, -- GitLab