Skip to content
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

Track all waitables that are currently in a wait set #207

Closed
nnmm opened this issue Jun 23, 2022 · 5 comments · Fixed by #224
Closed

Track all waitables that are currently in a wait set #207

nnmm opened this issue Jun 23, 2022 · 5 comments · Fixed by #224

Comments

@nnmm
Copy link
Contributor

nnmm commented Jun 23, 2022

During some refactoring to remove SubscriptionBase, I noticed that the wait set currently violates the unsafe code principles: Safe code can cause undefined behavior by adding the same item to multiple wait sets in different threads and waiting on them. From the rcl docs for rcl_wait():

This function is thread-safe for unique wait sets with unique contents.
This function cannot operate on the same wait set in multiple threads, and the wait sets may not share content.
For example, calling rcl_wait() in two threads on two different wait sets that both contain a single, shared guard condition is undefined behavior.

We need to either make all functions that end up calling rcl_wait() unsafe, like rclrs::spin(), or we need to guarantee that wait sets do not share contents. The latter could be done by having a global list of waitables that are currently in a wait set, and would be my favored approach.

@esteve
Copy link
Collaborator

esteve commented Jun 23, 2022

@nnmm

During some refactoring to remove SubscriptionBase

That is a major design decision, please file a ticket first so we can discuss this. A priori I'm not against, but I want to keep Subscription objects typed and I see how we can do that and remove SubscriptionBase.

@nnmm
Copy link
Contributor Author

nnmm commented Jun 23, 2022

@esteve I meant SubscriptionHandle, sorry. See #208

@esteve
Copy link
Collaborator

esteve commented Jun 23, 2022

@nnmm well, that PR also removes SubscriptionBase 😜

@nnmm
Copy link
Contributor Author

nnmm commented Jun 23, 2022

@esteve Yes, that title is a bit sloppily worded – it's more accurate to say it modifies and generalizes SubscriptionBase into Waitable. But the primary intent was to remove SubscriptionHandle.

@nnmm
Copy link
Contributor Author

nnmm commented Jun 25, 2022

Another option is to do what rclcpp does and have an atomic bool in_use_by_wait_set inside each subscription/waitable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants