gpt4 book ai didi

C++11 std::this_thread::sleep_until() 在使用 GCC 4.8.5 编译时挂起

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:13:44 28 4
gpt4 key购买 nike

考虑以下程序:

#include <chrono>
#include <thread>

int main() {
std::this_thread::sleep_until(std::chrono::steady_clock::now() - std::chrono::seconds(10));

return 0;
}

当用 GCC 4.8.5 编译时,它会挂起。用GCC 4.9及以上或clang3.4及以上编译时,立即返回,

为什么会挂?据我了解,GCC 4.8.5 完全支持 C++11 标准。

最佳答案

这是一个已确认的错误,已在 gcc 4.9 中修复。

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58038

When using sleep_until() I get an bug with unsigned long scalar representations of a duration. If this duratoiin is in past, then you get an overflow in the length of the argument for sleep_for(). This causes an almost infinte sleep, instead of a fast return.

关于C++11 std::this_thread::sleep_until() 在使用 GCC 4.8.5 编译时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47915034/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com