-
Notifications
You must be signed in to change notification settings - Fork 418
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
add start_canceled bool flag when creating a timer #2194
Conversation
This can be used to make sure that a timer is canceled before being registered with a node, avoiding the risk of race conditions if an executor tried to immediately trigger it Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additional test case would be nice to have.
@@ -90,15 +90,17 @@ create_timer( | |||
rclcpp::Clock::SharedPtr clock, | |||
rclcpp::Duration period, | |||
CallbackT && callback, | |||
rclcpp::CallbackGroup::SharedPtr group = nullptr) | |||
rclcpp::CallbackGroup::SharedPtr group = nullptr, | |||
bool start_canceled = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about the following? just a suggestion.
bool start_canceled = false) | |
bool auto_start = true) |
@@ -319,6 +319,23 @@ TEST_P(TestTimer, test_failures_with_exceptions) | |||
} | |||
} | |||
|
|||
/// Create a timer that starts as canceled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be probably better to add the test case that
- create canceled
timer
. - reset
timer
. (activate) - check timer callback is fired.
Is this a duplicate of #2005? |
Thanks for catching it! |
From a quick glance, it looks like the linked issue is part of a somewhat connected "web" of timer related issues. Edit* quick search + links below Timer issues -> PRs:
My only initial concern with keeping the other issue is it seems* a bit stale / older and this one could likely be merged more quickly. Edit* However, they aren't really that old (Dec of last year) and also include
With either choice (keeping this or the other), I agree with #2194 (comment) that |
@alsora how about closing this one and working on these open PRs? sorry i should have told you before... |
This can be used to make sure that a timer is canceled before being registered with a node, avoiding the risk of race conditions if an executor tried to immediately trigger it
Consider a situation where a user creates a timer but wants to activate it only at a later moment.
As soon as the timer object is created, the
rclcpp::create_timer
function would add it to the node timers interface, which would result in notifying the executor about this new entity.In case of thread starvation and/or race conditions, the executor may try to trigger the timer before it has been cancelled.
This could result in problems or crashes if the users were expecting that timer to not be called at that time.
This PR adds a boolean flag to the
rclcpp::create_timer
functions in order to cancel the timer in a safe way before adding it to the node timers interface.