Opened 4 years ago
Last modified 4 years ago
#13599 assigned Support Requests
condition_variable::timed_wait never returns
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | thread |
Version: | Boost 1.65.0 | Severity: | Problem |
Keywords: | Cc: |
Description
boost::condition_variable::timed_wait never returns if compiled with -DBOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC.
this_thread::sleep and thread::timed_join exhibit the same problem, but both these functions are documented as deprecated. However condition_variable::timed_wait is not documented as deprecated.
This can be worked around by using condition_variable::wait_for.
The following simple test program demonstrates the problem in that it hangs forever. Removing the #define makes it return after one second.
#define BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC #include <boost/thread.hpp> #include <iostream> int main( int argc, char* argv[] ) { boost::condition_variable cv; boost::mutex m; boost::mutex::scoped_lock lock( m ); cv.timed_wait( lock, boost::posix_time::seconds( 1 ) ); std::cout << "wait_for has returned" << std::endl; return 0; }
Change History (4)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 4 years ago
On which platform are you executing your program? Does the platform provide condition variables with monotonic clocks?
In principle, Boost.Thread defines BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC when know that this is the case. You should define it only if you are sure the platform provides it and Boost.Thread doesn't do it itself.
comment:4 by , 4 years ago
Type: | Bugs → Support Requests |
---|
Moved to support until we have answer to the questions
condition_variable::timed_wait
should be documented as deprecated.Thanks for the report anyway, I would try to fix it.