From 28e156c27f722190a7c41cff652a4319a368569a Mon Sep 17 00:00:00 2001 From: Huihuang Zheng Date: Wed, 13 Jan 2021 14:50:35 +0800 Subject: [PATCH] Fix Sleep Error in enforce.h (#30335) usleep function in only takes argument less than 1,000,000. Current call can exceed this limit, we have to fix it. This PR can fix random CI error. --- paddle/fluid/platform/enforce.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index c2ffed46e13..b11a32e3ac4 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -20,7 +20,7 @@ limitations under the License. */ #if !defined(_WIN32) #include // dladdr -#include // sleep +#include // sleep, usleep #else // _WIN32 #ifndef NOMINMAX #define NOMINMAX // msvc max/min macro conflict with std::min/max @@ -956,11 +956,19 @@ DEFINE_CUDA_STATUS_TYPE(ncclResult_t, ncclSuccess); } \ } while (0) -inline void retry_sleep(unsigned millisecond) { +inline void retry_sleep(unsigned milliseconds) { #ifdef _WIN32 - Sleep(millisecond); + Sleep(milliseconds); #else - usleep(millisecond * 1000); + if (milliseconds < 1000) { + // usleep argument must be less than 1,000,000. Reference: + // https://pubs.opengroup.org/onlinepubs/7908799/xsh/usleep.html + usleep(milliseconds * 1000); + } else { + // clip to sleep in seconds because we can not and don't have to + // sleep for exact milliseconds + sleep(milliseconds / 1000); + } #endif } -- GitLab