gpt4 book ai didi

c++ - 将 pos_infin 作为超时传递给 timed_wait 时,年份超出有效范围

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:59:23 25 4
gpt4 key购买 nike

以下代码重现了错误:

#include <iostream>
#include "boost/thread.hpp"
#include "boost/date_time/posix_time/ptime.hpp"

int main()
{
boost::condition_variable_any cv;
boost::timed_mutex m;

try {
{
boost::timed_mutex::scoped_timed_lock guard(m);
cv.timed_wait(guard, boost::posix_time::ptime(
boost::posix_time::pos_infin));
}
}
catch(std::exception & e) {
std::cout << "Error : " << e.what() << std::endl;
}
std::cout << "Done" << std::endl;

return 0;
}

在我的系统上,使用 Visual Studio 2005 和 Boost 1.43,这会产生以下输出:

Error : Year is out of valid range: 1400..10000
Done

我预计它会死锁,等待条件变量永远被通知。这似乎没有在任何地方记录,而且我希望 timed_wait 接受任何有效的 ptime。我做错了什么吗?这是一个错误,还是无限超时只是无意的?

最佳答案

使用 boost::posix_time::max_date_time 它将按预期工作。

关于c++ - 将 pos_infin 作为超时传递给 timed_wait 时,年份超出有效范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4678760/

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