未验证 提交 28e156c2 编写于 作者: H Huihuang Zheng 提交者: GitHub

Fix Sleep Error in enforce.h (#30335)

usleep function in <unistd.h> 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.
上级 017a5348
......@@ -20,7 +20,7 @@ limitations under the License. */
#if !defined(_WIN32)
#include <dlfcn.h> // dladdr
#include <unistd.h> // sleep
#include <unistd.h> // 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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册