On Thu, 29 Jun 2023 12:23:11 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> 
wrote:

>> Double-checked locking should rely on local variable to avoid racy reads 
>> from volatile field.
>
> The role of the local `keySet` seems pretty useless. It doesn't save neither 
> volatile reads nor writes.

@rgiulietti `keySet` is volatile, so providing it has already been initialized, 
in original code we read from it twice when doing null-check and returning the 
value. With local variable we read from the field only once, don't we?

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

PR Comment: https://git.openjdk.org/jdk/pull/14692#issuecomment-1613802472

Reply via email to