Trying to understand the scheduling architecture #3791
-
Hey! I'm currently trying to understand how Bevy guarantees safe access to all the components while still scheduling things across multiple threads. From browsing around the code I can see that systems get scheduled based on their sets and labels, but what still puzzles me is how does Bevy guarantee rust mutably rules when you have two systems which access a component mutably and a handful of other systems which access the same component immutably. In the
The comment above suggest that the systems may be scheduled together on one thread or could this only be referring to mutable access, but still allow for concurrent immutable access? If it's the latter how does bevy reconcile the exclusive and shared access? Is one expected to setup the system with careful planning to ensure there are no conflicts? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This guarantee is upheld automatically by the scheduler, which uses the signatures of your system functions to determine their access, and then only runs them if it won't conflict with any other system running at the same time. I'd recommend looking at #1144 for more details if you're curious. |
Beta Was this translation helpful? Give feedback.
-
@TheRawMeatball Thanks for the info, I think I sort of get the gist of it now. I still have one question though. If the systems check at run-time whether there are no conflicts with the current execution state and if we have the following example:
Is it possible that the order of these systems can be undefined? Assuming there's no other ordering restrictions, if system3 is chosen to run before system1, system1 can't run until system 3 finishes, but it's still possible for system 2 to run during this time. This in practice could lead to a case where system 1 will only be scheduled when all the reads A are finished. I guess this what the ambiguity log messages are for? |
Beta Was this translation helpful? Give feedback.
This guarantee is upheld automatically by the scheduler, which uses the signatures of your system functions to determine their access, and then only runs them if it won't conflict with any other system running at the same time. I'd recommend looking at #1144 for more details if you're curious.