-
Notifications
You must be signed in to change notification settings - Fork 529
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
Random.javaUtilConcurrentThreadLocalRandom not thread-local #2766
Labels
Comments
That is a valid point and should be fixed. Feel free to open a PR. |
This is actually a great first issue. Fixable just by collapsing the two |
I allowed myself to try to fix the issue. I hope that's fine with @durban . |
@PiotrBosak Sure, absolutely :-) |
Btw this would have been another possible application of #2610. |
This was fixed by #2784. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that
cats.effect.std.Random.javaUtilConcurrentThreadLocalRandom
might call aThreadLocalRandom
from the incorrect thread. Its unlikely this would cause any problems on OpenJDK, since there everyThreadLocalRandom
is the "same", but... it's still not allowed, and who knows what other JVM-s might do.I think this could happen in the following way. Inlining a few things, what it does is like this:
So there is a
flatMap
between the call to.current()
and (for example) the call to.nextBoolean()
. And if there is an "autocede" between them, the fiber could be rescheduled to another JVM thread. And then.nextBoolean()
would be called on another thread'sThreadLocalRandom
. At least I think this could happen.The text was updated successfully, but these errors were encountered: