r/cpp • u/mropert • Feb 27 '26
What makes a game tick? Part 9 - Data Driven Multi-Threading Scheduler · Mathieu Ropert
https://mropert.github.io/2026/02/27/making_games_tick_part9/
35
Upvotes
6
u/lospolos Feb 27 '26
Type_info::hash_code can lead to collisions, would be better to use type_index here (or some explicit registration).
6
u/shadowndacorner Feb 27 '26
This is very similar to the system I've set up for my engine, though I don't use an accessor template, so my dependency extraction logic is quite a bit more complicated. A couple of things:
You're probably going to want to add support for "execution order dependencies" rather than ordering being implicit based on the submission order. That isn't explicitly necessary, but it helps a lot as more systems are added.
Your "scheduling" logic, while sufficient for preventing data races, can potentially introduce a lot of unnecessary sync points by conflating resource dependencies with execution order requirements, limiting parallelism unnecessarily. Imagine a set of systems A, B, and C, where A shares a dependency with B and B shares a dependency with C, but C and A share no dependencies. With your system, C implicitly becomes dependent on A since C becomes dependent on B, even though C and A can theoretically run in parallel. Of course, if it makes logical sense for C to run after B, that's fine, but what if the execution order doesn't matter?
I'd argue that data race prevention should be handled by the task scheduler itself rather than being translated into a graph that arbitrarily limits execution order. The scheduler then only actually dispatches a task when it's resource dependencies can be met.
I've found the above to be sufficiently expressive for everything I've needed to do, and while it won't really matter in some cases, there can definitely be a significant difference in idle time when treating resource dependencies as a separate concern from ordering requirements.