开发者

Year is out of valid range when passing pos_infin as timeout to timed_wait

开发者 https://www.devze.com 2023-02-03 19:58 出处:网络
The following code reproduces the error: #include <iostream> #include \"boost/thread.hpp\" #include \"boost/date_time/posix_time/ptime.hpp\"

The following code reproduces the error:

#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;
}

On my system, using Visual Studio 2005 and Boost 1.43, this produces the following output:

Error : Year is out of 开发者_C百科valid range: 1400..10000
Done

I would expect it to deadlock, waiting for the condition variable to be notified for all eternity. This does not seem to be documented anywhere, and also I would expect timed_wait to accept any valid ptime. Am I doing anything wrong? Is this a bug, or are infinite timeouts just not intended?


Use boost::posix_time::max_date_time and it'll work as expected.

0

精彩评论

暂无评论...
验证码 换一张
取 消