-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: x/exp/rand: Make LockedSource zero value useful #49342
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
Comments
/cc @robpike |
This seems good to me. I'm happy to accept a change. |
Change https://go.dev/cl/385094 mentions this issue: |
Sent a CL. FWIW, I don't know what the plans for
I suggested this solution, because #25988 was put on hold for changing the API, so I didn't want to do that. But IMO better options would be (in order of preference)
I bring this up now, because currently no program actually uses |
Previously, #25988 was put on hold, because API changes to
x/exp/rand
where hold off on. I'm running into the same problem right now. I would assume that over the last three years the decision of whether or not we want to changemath/rand
for Go 2 has manifested a bit more.My proposal is less of an API change. Instead of adding a
NewLockedSource
function, I'd suggest to changeLockedSource.src
from a pointer into a value. The methods onLockedSource
have pointer-receivers, so we'd still be able to call pointer-methods on it. This would both makesrc.Seed
work on a zero-valueLockedSource
and remove a pointer indirection.The reasons I want to use a
LockedSource
are the same as @krancour mentions in the above issue:That is exactly the trade-off I've run into a couple of times now. For now, I'll probably use a package-scoped
sync.Pool
, but it would be great if we could just get a package-scoped, concurrency-safe*rand.Rand
.Also, I think if we don't add either a constructor or do something like this proposal, we should remove
LockedSource
again. There is no benefit to exporting a type which can't be used.The text was updated successfully, but these errors were encountered: