On Tue, 21 Jul 2026 06:10:44 GMT, David Holmes <[email protected]> wrote:

>> This PR proposes to fix a race condition.
>> 
>> ---------
>> - [X] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/java.base/share/classes/java/util/LazyCollections.java line 680:
> 
>> 678:             // There might be a race where the value is already 
>> computed and
>> 679:             // the mutex is cleared, so we need to re-check the value 
>> again
>> 680:             final T t = (T) UNSAFE.getReferenceAcquire(array, offset);
> 
> It is not obvious to me from the code below that the setting of the value and 
> the clearing of the "mutex" are guaranteed to be ordered i.e. you might see a 
> null mutex and also not see the new value.

Right, `acquireMutex` returns `null` when the `mutexes` array is `null`, but it 
is written and read using plain writes/reads. I think if we want a guarantee 
that setting the `mutexes` to `null` is ordered after the set of the value, it 
should use a `putReferenceRelease`, and likewise, reading it in `acquireMutex` 
should use `getReferenceAcquire`.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31979#discussion_r3623024005

Reply via email to