-
Notifications
You must be signed in to change notification settings - Fork 16
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 a reference-counted version of SampleMut
#61
Conversation
Allows to create owned samples when the publisher is reference-counted.
I'm not sure if GitHub sends out any notification for draft PRs, so cc @elBoberido. |
@phil-opp Thanks for the PR and the ping! @elBoberido is on vacation this week. He'll be back in CW41. |
Thanks for the notice! There is no rush, I just wanted to make sure that this PR is noticed. |
@phil-opp thanks for trying to improve the iceoryx Rust binding :) May I ask for the use case you want to address? I just skimmed over the PR and did not yet do a proper review. Is your intention to publish from multiple threads or just to be able to access the sample from multiple threads? |
@phil-opp btw. I just realized who you are. I read a few of your blog posts. Great stuff :) |
@elBoberido Thanks a lot :).
Our main use case is passing the sample over an FFI boundary to let a shared library fill in some data without copying. This is much safer with owned data because lifetimes are lost at the FFI boundary.
The PR is just a first draft that copies most of the If such a reference-counted sample type is okay with you, I'll try to remove some of the duplication in the implementation. |
@phil-opp so you basically need it for FFI. Would something similar to the untyped C++ API which uses |
Yeah, that would help for our use case! And it should be much simpler to implement. I still think that a reference-counted sample type would be useful too. There are other non-FFI use cases that would profit from such a type. For example, consider an actor framework that communicates using mpsc channels. In such a system, an IPC actor could be responsible for communicating with other processes via iceoryx. Other actors could then request a sample from the IPC actor, fill in their data, and send the filled sample back to the IPC actor for publishing. This approach does not work with borrowed data, so it might make sense to add support for an owned/reference-counted sample type in the future. |
@phil-opp good point. That's definitely a good use case but it is not as easy as it seems. The problem is that the underlying publisher is not thread safe which means loaning, publishing and releasing must happen from the same thread. While this is not a problem for loan and publish, it is a problem for release since the destructor of ref-counted sample type could call the publisher from any thread and corrupt the publisher. I was quite happy that this is not possible with the Rust binding but while typing this, I might have introduced this unsoundness in the subscriber. I have to take a look for that. Anyway, I will think of a possible API for the raw pointer access. If you have an idea, don't hesitate to write a proposal. Btw. tomorrow is our bi-weekly developer meetup. Would be great to have you there :) Out of curiosity, can you reveal what you are using iceoryx for and are there other missing APIs for your use case? |
Ah, that makes things more difficult. I guess I can close this PR then as it would result in undefined behavior.
Thanks! Maybe a
Ah sorry, I just read the notification email today...
We're currently evaluating iceoryx for the https://github.com/dora-rs/dora project. Our goal is to support multiple pub/sub backends to support different use cases. For example, we also support I don't think that we're missing any other APIs right now. Waiting for multiple subscribers at once (#9) would be useful to us, but not critical. |
Yes, I think this PR can't be merged and it would be easier to start from scratch than to try to refactor the current code.
Yes, this should work. I'm not sure if we need the thread ID. One could wrap the publisher in a mutex and then it would be save to publish from multiple threads. I have to think more about this. I like the idea with the The PR is not ideal for design discussions. I asked the eclipse helpdesk to enable the github Diskussions feature. I think that a bit better. I just had another idea. Since loan and publish is already safe due to the type system, we would just need to make the release of a sample thread safe. This could be done with a multi pusher single consumer queue. When a sample is dropped, it would not directly call the publisher to release the underlying memory chunk but instead push it into the queue. The next time loan is called, the publisher could then release the sample or even reuse it since it would still be the owner. The memory would not be immediately released but this shouldn't be a big issue. cc @elfenpiff maybe you also have some ideas?
No problem. There is one every second week. If you are interested, we can put this topic on the agenda for next week.
Sound great. We are currently also thinking about getting in contact with the zenoh guys to explore if they are interested in using iceoryx in zenoh for local transport. If a day wouldn't be limited to just 24 hours 😅
Good to know. I already hacked something together but it's far from ready. |
Ok, I'll close the PR then.
Which API do you mean exactly?
Looks like it's up: https://github.com/eclipse-iceoryx/iceoryx-rs/discussions. Should we create a discussion thread there?
Interesting idea! What would happen if the publisher is dropped before the sample? Then the queue would be closed already.
That would be cool! I think they also have a custom shared memory implementation, e.g. used in this example. I'm not sure how their design compares to iceoryx, but it might be interesting to explore this further.
Cool, let me know if I can do anything to help. |
Something like
Right. This won't work as long as the lifetime of the sample is coupled to the publisher. There are ideas to couple it to the lifetime of the runtime and then this approach would work.
Currently I'm thinking if something similar to the C++ |
Allows to create owned samples when the publisher is reference-counted.
Note: This is only a first draft to request feedback. I'm happy to polish this PR if this change is desired.
Pre-Review Checklist for the PR Author
rustfmt
iox-123-this-is-a-branch
)iox-#42 commit text
)task-list-completed
)Notes for Reviewer
Checklist for the PR Reviewer
Post-review Checklist for the PR Author
References