Skip to content

Is this per CPU or per goroutine? #4

@qdm12

Description

@qdm12

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions