Skip to content
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

Closed
zicklag opened this issue Nov 12, 2023 · 1 comment
Closed

No Need to Spawn Thread in a par_iter() #1

zicklag opened this issue Nov 12, 2023 · 1 comment

Comments

@zicklag
Copy link
Collaborator

zicklag commented Nov 12, 2023

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 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.

@zicklag
Copy link
Collaborator Author

zicklag commented Nov 20, 2023

Closing as we're not doing this anymore.

@zicklag zicklag closed this as completed Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant