I'm trying to use condition_variable_any::timed_wait()
When I pass a boost::chrono::millisecond
into the function, it fails to compile:
error: no match for ‘operator+’ in ‘boost::get_system_time() + wait_duration’
However if I pass boost::posix_time::milliseconds
into the function it does compile.
The problem is I don't understand the difference between the two. They both claim to be durations. But As I understand posix time, it is representative of the time since the epoch, which to me means that boost::posix_time::milliseconds p(1000)
is representative of the time at 1 second after the epoch. I don't see this as a duration.
What am I missing? Can someone please explain the differences?
I'll give a stab at it, though I'm not the developer or part of the standards committee.
Boost is a playground for ideas that may one day get integrated into the standard library. As such, it often has quirks in it that you wouldn't see in other places.
boost::posix_time is a wrapper around the posix_time datastructure. POSIX (Portable Operating System Interface) is a set of standards given by IEEE in attempt to get all operating systems and programs to speak in a similar language (spoiler, they don't). POSIX defines a fixed-point numeral system for time and time differences, though the resolution of that structure varies. In BOOST, the resolution is configurable at compile time. The goal of the library is to more easily manipulate POSIX complient time strucures. Introduced before 1.31.
boost::chrono (integrated into C++11 as std::chrono) is a generic time-scale library. The goal was to have a set of functions and structures that can deal with time well and allow the user to configure the underlying datatype. No effort was made to be in line with any standard. Introduced in 1.51.
While this is (100%) two libraries to do the same thing, they do it in a slightly different way. In a system like boost, this is arguably unavoidable: with new language features and programming requirements, you'll probably want to completely refractor some things but need to keep (somewhat) backwards compatibility. But it leads to a weird problem: different implemtation, just to confuse you. Because POSIX time is simply so much older, most interfaces (like condition_variable_any::timed_wai) only have a posix_time interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With