Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

condition_variable::timed_wait incompatible with std::chrono::duration due to lack of is_pos_infinity #410

Open
SpareSimian opened this issue Dec 4, 2024 · 2 comments

Comments

@SpareSimian
Copy link

boost::condition_variable::timed_wait() attempts to invoke wait_duration.is_pos_infinity() on its templated parameter.

The standard doesn't define a member is_pos_infinity expected by timed_wait, forcing one to use a Boost clock rather than an STL one such as steady_clock or system_clock.

https://en.cppreference.com/w/cpp/chrono/duration

Found when compiling with MSVS 2022's STL (line 200 here):

https://github.com/microsoft/STL/blob/main/stl/inc/__msvc_chrono.hpp

A possible workaround would be to define an adapter class that defines this member.

@SpareSimian
Copy link
Author

I thought perhaps BOOST_THREAD_USE_CHRONO would fix this but the following simple program fails to compile:

#define BOOST_THREAD_USE_CHRONO
#include <iostream>
#include <chrono>
#include <boost/thread/condition_variable.hpp>

int main()
{
   return 0;
}

typedef std::chrono::system_clock Clock;
typedef Clock::duration TimeDuration;
typedef Clock::time_point TimePoint;

void foo(boost::mutex& mutex, boost::condition_variable& cv, TimePoint expireTime)
{
   boost::unique_lock<boost::mutex> lock(mutex);
   cv.timed_wait(lock, expireTime);
}

@SpareSimian
Copy link
Author

I tried substituting boost::chrono::system_clock and I got the same errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant