Skip to content

Commit

Permalink
roscpp: use boost::condition_variable::wait_for() instead of deprecat…
Browse files Browse the repository at this point in the history
…ed timed_wait()

This fixes ROS timers in combination with 2c18b9f. The timer
callbacks were not called because the TimerManager's thread function blocked indefinitely on
boost::condition_variable::timed_wait().

Relative timed_wait() uses the system clock (boost::get_system_time()) unconditionally to
calculate the absolute timestamp for do_wait_until(). If the condition variable has been
initialized with BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC, it compares this timestamp
with the monotonic clock and therefore blocks.

This issue has been reported in https://svn.boost.org/trac10/ticket/12728 and will not be
fixed. The timed_wait interface is apparently deprecated.
  • Loading branch information
meyerj committed Dec 6, 2018
1 parent 2c18b9f commit 56ecdfa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion clients/roscpp/include/boost_161_condition_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace boost_161 {
using condition_variable = boost::condition_variable;
}
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
//#include <boost/thread/pthread/condition_variable.hpp>
#include "boost_161_pthread_condition_variable.h"
#else
#error "Boost threads unavailable on this platform"
Expand Down
4 changes: 2 additions & 2 deletions clients/roscpp/include/ros/timer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,14 @@ void TimerManager<T, D, E>::threadFunc()
// since simulation time may be running faster than real time.
if (!T::isSystemTime())
{
timers_cond_.timed_wait(lock, boost::posix_time::milliseconds(1));
timers_cond_.wait_for(lock, boost::chrono::milliseconds(1));
}
else
{
// On system time we can simply sleep for the rest of the wait time, since anything else requiring processing will
// signal the condition variable
int64_t remaining_time = std::max<int64_t>((sleep_end - current).toSec() * 1000.0f, 1);
timers_cond_.timed_wait(lock, boost::posix_time::milliseconds(remaining_time));
timers_cond_.wait_for(lock, boost::chrono::milliseconds(remaining_time));
}
}

Expand Down

0 comments on commit 56ecdfa

Please sign in to comment.