-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Non send as thread marker + TLS #6657
Conversation
If It seems like exclusive systems can just have a non-send marker param, but I'm not sure about commands. Would those just be unable to access the data? |
In the current PR + pipelined rendering you could do: fn my_exclusive_system(world: &mut World) {
let main_thread_executor = world.get_resource::<MainThreadExecutor>();
ComputeTaskPool::get().scope_with_executor(false, main_thread_executor.clone(), |scope| {
let tls = world.get_resource::<Tls<MyResource>>();
scope.spawn_on_scope(async move {
tls.get(|tls| {
/* do something with the tls */
});
});
});
} This solution would work for normal systems too and is pretty close to your recommended solution.
So this is a little weird. The way the lib works is that it's just a thread local hashmap and the thing that gets stored in the world is just the key into the hashmap. So if we called remove::<Tls>() what actually happens is that the key is dropped, but the actual data in the TLS would only get dropped when the thread exits. The story around dropping is probably the biggest outstanding issue in this PR. I shimmed a drop impl onto Tls, but that only really cleans up the tls on the thread the To be clear I think of this PR + the |
I understand how
(edited)
(edited) I really think that the This PR feels like a longer route to that same conclusion. fn my_system(main_thread: Res<ThreadLocal<Main>>) {
// access specific resource
main_thread.run(|res: &mut MyResource| {
res.0 = 1;
});
// or access entire TLS
main_thread.run(|tls: &mut TLS| {
// drop a resource normally
tls.remove_resource::<MyResource>();
});
} I don't think I'm describing this very well, so I'll try to submit a PR for comparison. (edited) |
Objective
Solution
Changelog
Migration Guide
before:
after:
Notes
Keeping this in draft until a decision has been made on what solution we want. This needs to be cleaned up a bit more before being merged.