-
Notifications
You must be signed in to change notification settings - Fork 407
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
Documentation Request: Thread Safety Guarantees for Publisher APIs #2417
Comments
@owny990312 By default, all classes are not threadsafe unless it is explicitly stated in the documentation. You should also avoid moving classes between threads. So the So this is not allowed in iceoryx: // publisher
auto sample = publisher.loan().expect("loaned sample successfully");
// forbidden, since the sample access under the hood the publisher which is not threadsafe
std::thread my_thread([sample = std::move(sample)](){
*sample = 123;
}); The same applies to the subscriber. |
Thanks for your reply. When there are two subscribers (either in different processes or threads) subscribing to the same topic, and both are waiting for data from the same publisher, if we use subscriber->release(), could this scenario occur: after the first subscriber receives and releases the data, the second subscriber might get empty or invalid data, potentially leading to undefined behavior? |
No, two different subscribers do not cause any problems. If every subscriber is used correctly, you can have arbitrarily many subscribers in arbitrarily many threads and do whatever you want with them. |
Thanks for your reply. |
I'm using the iceoryx publisher APIs and have questions about their thread safety guarantees. Specifically:
Current Situation
In
UntypedPublisherImpl
, there are three core APIs:loan()
publish()
release()
However, I couldn't find clear documentation about their thread safety guarantees.
Questions
Are these APIs thread-safe in
UntypedPublisherImpl
?loan()
concurrently?publish()
on different chunks concurrently?release()
on different chunks concurrently?Do these thread safety guarantees (if any) apply to all publisher types in iceoryx?
If these APIs are thread-safe:
Request
Could you please:
This information would be very helpful for users implementing multi-threaded publishers in their applications.
Additional Context
The text was updated successfully, but these errors were encountered: