【问题标题】:Year is out of valid range when passing pos_infin as timeout to timed_wait将 pos_infin 作为超时传递给 timed_wait 时,年份超出有效范围
【发布时间】:2011-01-13 10:02:04
【问题描述】:

以下代码重现了错误:

#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。我做错什么了吗?这是一个错误,还是无意无限超时?

【问题讨论】:

  • 无法在 1.45.0 的 linux 上重现。如果在 1.45.0 中修复,您可以试试吗?
  • 我会先安装它,所以需要一点时间。
  • @chris:我查了一下,1.45也出现了错误。
  • @Space_C0wb0y 它不会为我在 Mac OS X 上使用 boost 1.45 进行复制。不过,对于复制器 +1。
  • 用 Visual Studio 2010 和 boost 1.46.1 复制

标签: c++ boost boost-thread condition-variable boost-date-time


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 2015-01-07
    • 1970-01-01
    相关资源
    最近更新 更多