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

Is this per CPU or per goroutine? #4

Open
qdm12 opened this issue Mar 21, 2021 · 0 comments
Open

Is this per CPU or per goroutine? #4

qdm12 opened this issue Mar 21, 2021 · 0 comments

Comments

@qdm12
Copy link

qdm12 commented Mar 21, 2021

Hello, first thanks for that small code, it's interesting!

I'm trying to solve this with it, for the fun of it.

Now regarding the sync.Pool, I'm not sure this is so much per CPU than it is per goroutine.

If you have 1000 goroutines at the same time, there will be 1000 RNG objects (well just 1000x 1 uint32 really so that's fine memory wise).

Indeed if you have 4 CPU intensive goroutines on a 4 core CPU, there will be one RNG per core but that's a particular case.

Should we mention that in the readme?

There is also another problem: if you launch 1000 goroutines at start, it 'could' create 1000 RNG initialized with the same time (unlikely, but it can happen on certain systems with bad time resolution) and that can lead to a quite bad pseudo randomness.

Maybe a solution would be to use crypto/rand the first time when creating the RNG object via the sync.Pool's New field function?

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