I'm making a parallel ECS, and I'm building the scheduler for running the systems in parallel. Heres what the Scheduler looks like:
struct Scheduler {
systems: Vec<Node>,
}
struct Node {
// the function that will be run
system: Box<dyn System + Send + Sync>,
// the data that this system accesses
// "Accessor" is an enum. Used to compute systems that conflict with this one
access: Vec<Accessor>,
// Contains all the systems without any conflicts.
edges: Vec<usize>,
}
Each Node contains a System. Whenever a Node is created, I compute all the other systems which will not conflict with the System when ran. This will allow me run them in parallel if possible without the risk of deadlock.
Here's my code for executing the systems:
pub fn execute(&mut self, engine: Arc<Engine>) {
// for every system...
for i in 0..self.systems.len() {
// if it has not been ran...
if !self.systems[i].has_ran {
// run the system
rayon::spawn(|| self.systems[i].system.execute(engine.clone())); // <-- error occurs here
// spawn threads for every system in `edges`, not implemented yet.
}
}
}