diff --git a/paddle/fluid/framework/new_executor/nonblocking_threadpool.h b/paddle/fluid/framework/new_executor/nonblocking_threadpool.h index 6e56532456c6fd6b5cfbb4a14601e1e335495e73..cdcdbbb445185bc9a8b04125813b49c959dd0b85 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,