-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Replace some !Send
resources with thread_local!
#17730
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
Conversation
This reverts commit 0319455.
b0e821c
to
38ffe2c
Compare
1a9c211
to
789a9bf
Compare
789a9bf
to
df85779
Compare
Won't this cause multiple worlds to share the same |
Yes, in theory multiple worlds could share these resources. However, in practice in this PR, that is not happening. Keep in mind, I am not changing the API in any way. I am only changing how a few internal variables are stored. |
@alice-i-cecile, just pinging you here for review on GitHub as well, in case that's your preferred workflow |
!Send
resources with thread_local!
!Send
resources with thread_local!
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.
Looks good!
751410f
to
a114044
Compare
a114044
to
c62693c
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.
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.
Changes are fairly straightforward. I think passing the EventLoop
through a closure makes way more sense than smuggling it through a non send resource. My one worry is that nothing is forcing the gilrs systems to run on the main thread anymore other than the fact that wasm is single threaded. Maybe not too big of a deal though as it'll just panic with the thread local not being initialized and should be easy to fix if we do get wasm multithreading.
gilrs uses EDIT1: Was there some reason why you used
Agreed. I think this will help. However, the Allowing the |
I don't recall ever discussing that, so I'm going to say no. Looking at the gilrs code, I see your concern for using
You are correct. This PR does not completely get rid of
Correct me if I'm wrong, but I believe the world is |
# Objective Remaining work for and closes #17682. First half of work for that issue was completed in [PR 17730](#17730). However, the rest of the work ended up getting blocked because we needed a way of forcing systems to run on the main thread without the use of `!Send` resources. That was unblocked by [PR 18301](#18301). This work should finish unblocking the resources-as-components effort. # Testing Ran several examples using my Linux machine, just to make sure things are working as expected and no surprises pop up. --------- Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com> Co-authored-by: François Mockers <francois.mockers@vleue.com>
# Objective Remaining work for and closes bevyengine#17682. First half of work for that issue was completed in [PR 17730](bevyengine#17730). However, the rest of the work ended up getting blocked because we needed a way of forcing systems to run on the main thread without the use of `!Send` resources. That was unblocked by [PR 18301](bevyengine#18301). This work should finish unblocking the resources-as-components effort. # Testing Ran several examples using my Linux machine, just to make sure things are working as expected and no surprises pop up. --------- Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com> Co-authored-by: François Mockers <francois.mockers@vleue.com>
Objective
Work for issue #17682
What's in this PR:
!Send
resources that Bevy uses internally!Send
resources withthread_local!
staticWhat this PR does not cover:
!Send
resources still exists!Send
resources are present (and should not be removed until the ability to create!Send
resources is removed)log_layers_ecs
still uses a!Send
resource. In this example, removing the!Send
resource results in the system that uses it running on a thread other than the main thread, which doesn't work with lazily initializedthread_local!
static data. Removing this!Send
resource will need to be deferred until the System API is extended to support configuring which thread the System runs on. Once an issue for this work is created, it will be mentioned in 🐢 Eliminate!Send
resources by supportingSend
and!Send
World
in the same binary #17667Once the System API is extended to allow control of which thread the System runs on, the rest of the
!Send
resources can be removed in a different PR.