-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
No Need to Spawn Thread in a par_iter()
#1
Comments
Closing as we're not doing this anymore. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: