RFR: 8261445: Use memory_order_relaxed for os::random().
Martin Doerr
mdoerr at openjdk.java.net
Tue Feb 9 18:52:39 UTC 2021
On Tue, 9 Feb 2021 18:22:36 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>
>
> It seems superficially fine, given unsynchronized read of `_rand_seed` prior to that. But I have to wonder if in absence of any memory ordering semantics, this loop is guaranteed to terminate? That is, can't a sufficiently hostile optimizer reduce it to the CAS loop that always expects a constant "oldval" seed?
I can't see any problem here. `_rand_seed` is volatile so the compiler must preserve all accesses to it. And all processors I'm aware of are single-copy atomic which means that all accesses to the same memory location are ordered.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2484
More information about the hotspot-runtime-dev
mailing list