-
Notifications
You must be signed in to change notification settings - Fork 417
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
Timer class methods aren't thread safe #1025
Comments
Could you please add the description of what the bug is to this issue description? |
I mean in the top post - the top comment right now is basically just a link, and well, it should describe the issue What functions aren't threadsafe that should be? All instance methods of Are there any observed behavioral problems or test failures that have been linked with this issue? |
Done. If you read the old comment the post description was linking, it says almost the same thing.
All the ones that access this member variable: rclcpp/rclcpp/include/rclcpp/timer.hpp Line 106 in 96ebf59
No, my complain is just theoretical now. |
I doubt I get to this before the API freeze, What's the expectation here for triage? I don't think we need to investigate anything right? I'd either put it on the foxy board or backlog. If on the foxy board we can randomly assign it to me, but again, it will be after API freeze before I have any time. |
FYI: not directly related to timers, but I did catch a case where the rclcpp API ( I think we need a broader effort to instrument and report unsafe usage of functions that are not threadsafe. |
I believe that the timer class is thread safe because all of the functions that use I'm not sure why some of the code-blocks below aren't importing correctly.
|
{ | |
std::lock_guard<std::mutex> clock_guard(clock_->get_clock_mutex()); | |
if ( | |
rcl_timer_init( | |
timer_handle_.get(), clock_handle, rcl_context.get(), period.count(), nullptr, | |
rcl_get_default_allocator()) != RCL_RET_OK) | |
{ | |
RCUTILS_LOG_ERROR_NAMED( | |
"rclcpp", | |
"Couldn't initialize rcl timer handle: %s\n", rcl_get_error_string().str); | |
rcl_reset_error(); | |
} | |
} |
rcl_timer_cancel
rclcpp/rclcpp/src/rclcpp/timer.cpp
Line 83 in cc65905
if (rcl_timer_cancel(timer_handle_.get()) != RCL_RET_OK) { |
Documentation:
rcl_timer_is_canceled
rclcpp/rclcpp/src/rclcpp/timer.cpp
Line 92 in cc65905
rcl_ret_t ret = rcl_timer_is_canceled(timer_handle_.get(), &is_canceled); |
Documentation:
rcl_timer_is_ready
rclcpp/rclcpp/src/rclcpp/timer.cpp
Line 111 in cc65905
if (rcl_timer_is_ready(timer_handle_.get(), &ready) != RCL_RET_OK) { |
Documentation:
rcl_timer_get_time_until_next_call
Documentation:
Returning timer_handle_
I don't believe anything should be done here.
rclcpp/rclcpp/src/rclcpp/timer.cpp
Line 136 in cc65905
return timer_handle_; |
timer_handle_
usages in timer.hpp
rclcpp/rclcpp/include/rclcpp/timer.hpp
Line 201 in cc65905
rcl_ret_t ret = rcl_timer_call(timer_handle_.get()); |
Documentation:
Thanks for your analysis, I believe it's correct.
I don't like much using the mutex of another object, though reading the implementation this is unfortunately needed (a refactor in
Code blocks from other repositories aren't rendered. It seems that this was only a false alarm from my side, so I will close the issue. |
Feature request
Feature description
Methods are using
timer_handle_
member variable without adding any kind of thread-safe protection, e.g.:rclcpp/rclcpp/src/rclcpp/timer.cpp
Line 83 in 96ebf59
rcl
functions aren't thread safe, so astd::mutex
(or maybestd::recursive_mutex
) should be added to protect concurrent access oftimer_handle_
.See #1013 (comment).
Implementation considerations
The text was updated successfully, but these errors were encountered: