以下代码重现该错误:
#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,它将按预期工作。