-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Implement InstanceStorage optionally as sync for #18 #212
Conversation
Thanks a lot for driving this topic forward! 🙂 It looks like this PR enables Can you describe a bit the use case you had that inspired this approach? Which situations require sharing of |
I'm currently accepting a Gd instance of a struct that is being created in GDScript. In a method call, I then create a parallel iterator that accesses To make all this work, I have a To my understanding the How would it be possible to access the base of |
Many options:
That's kind of what makes the whole threading so complex: we need to take into account that the Godot engine holds references to our types. The gdnative library addressed this via |
In my opinion, the only sensible approach here would be to uphold borrowing rules for the rust code but make no guarantees for anything happening in C++ / Godot. As you say, there is no reliable way to perform runtime checks. Do you see any value in this patch as it is right now? |
I found something we might be able to use. It seems like Godot allows us to attach an "InstanceBinding" to our objects. using These InstanceBinding objects allow us to set callbacks which Godot will call whenever it:
With this i feel like we should be able to do something to ensure memory safety. It does unfortunately seem like the reference callback only runs for RefCounted objects, however the free callback runs for every object. edit: actually the reference callback runs both when godot references and unreferences a RefCounted object, passing along a bool to indicate which happened. I'm not sure if that'll be very useful but good to know. |
Definitely, I think it's a good first step toward exploring multi-threading. Maybe we should just start somewhere -- even if an implementation is not solving all the issues, it's probably better to work on this iteratively than plan out a huge design (which may easily miss things as well). It can however well happen that we later completely change the way how we approach threads, I hope you'd be fine with breaking changes too 🙂 Question regarding pub struct GdRef<'a, T> |
bf7f29b
to
65e552c
Compare
@Bromeon I removed the generic parameter |
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.
Thanks for the conditional compilation changes!
Regarding CI, we need to be careful to avoid combinatoric explosion for different features (we had similar discussion for the double-precision
). This would currently add 6 new CI jobs just for multi-threading, and we don't even actively test much.
So I'd recommend to do the following for now:
- Leave
unit-test
unchanged frommaster
, there are no unit tests even testing this. - For
godot-itest
, instead of a 3x2 matrix, just add a single extra configuration toinclude:
- This should be a Linux runner, with the
threads
feature flag.
- This should be a Linux runner, with the
Since threading is in a very early stage, I wouldn't spend too much compute resources (time, not money) on them. We can always adapt this over time.
65e552c
to
91f5e82
Compare
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.
Thanks a lot for this first step towards threading!
bors r+
212: Implement InstanceStorage optionally as sync for #18 r=Bromeon a=TitanNano This is a second implementation of `InstanceStorage` that is `Sync` and `Send` and should make it suitable for usage with rust threads. I hope it fits with the general plans for multithreading in #18. Feedback is more than welcome. Co-authored-by: Jovan Gerodetti <[email protected]>
Build failed: |
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.
CI failed, the artifact name was wrongly assumed to be linux-threads
.
Corrected line in suggestion.
bors r+ |
212: Implement InstanceStorage optionally as sync for #18 r=Bromeon a=TitanNano This is a second implementation of `InstanceStorage` that is `Sync` and `Send` and should make it suitable for usage with rust threads. I hope it fits with the general plans for multithreading in #18. Feedback is more than welcome. Co-authored-by: Jovan Gerodetti <[email protected]> Co-authored-by: Jan Haller <[email protected]>
Build failed: |
bors r+ |
Build succeeded: |
This is a second implementation of
InstanceStorage
that isSync
andSend
and should make it suitable for usage with rust threads.I hope it fits with the general plans for multithreading in #18. Feedback is more than welcome.