When you use rayon to do a par_iter(), you don't actually need to spawn any threads yourself, because rayon automatically runs your for_each() closure on it's own thread pool.
Spawning threads actually takes some time, because it has to start a new OS process, so what rayon does is create one thread for every CPU core that you have, and then it re-uses those threads to do all of it's work, automatically running your code on it's pre-created threads, so that you don't have to think about it.
The par_iter() won't return until all the jobs are finished, either, so that removes the need to wait for any thread handles or anything like that. That's what's nifty about rayon, you hardly have to think about the threads, you just change iter to par_iter for the most part.
PS: I'm going to be looking at doing the direct write to GPU textures, so I'll have to change this code in a PR if I get to it, so you may not want to change it right away.
https://github.com/Zac8668/democritus/blob/2f4e1bf5b0387b8dbcd72d3937ea77fdcc5615d9/src/grid.rs#L163-L165
When you use rayon to do a
par_iter()
, you don't actually need to spawn any threads yourself, because rayon automatically runs yourfor_each()
closure on it's own thread pool.Spawning threads actually takes some time, because it has to start a new OS process, so what rayon does is create one thread for every CPU core that you have, and then it re-uses those threads to do all of it's work, automatically running your code on it's pre-created threads, so that you don't have to think about it.
The
par_iter()
won't return until all the jobs are finished, either, so that removes the need to wait for any thread handles or anything like that. That's what's nifty about rayon, you hardly have to think about the threads, you just changeiter
topar_iter
for the most part.PS: I'm going to be looking at doing the direct write to GPU textures, so I'll have to change this code in a PR if I get to it, so you may not want to change it right away.