On Wed, 23 Apr 2025 17:36:25 GMT, Alan Bateman <al...@openjdk.org> wrote:

>> src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java 
>> line 182:
>> 
>>> 180:             clone.setMap(new ConcurrentSkipListMap<E,Object>(m));
>>> 181:             // Needed to ensure safe publication of setMap()
>>> 182:             VarHandle.releaseFence();
>> 
>> @DougLea This might be interesting to you. 👍
>
> I wonder if we could just change it to return `new 
> ConcurrentSkipListSet<>(m)`. COWAL could be changed to return a new object 
> too.

The set only has a map field, and AbstractSet does not define any additional 
field. The map should be fine too - two fields in AbstractMap are cleared when 
cloning happens, so recreating a map from a constructor should have the same 
effect. (Note a significant field `head` is not cleared upon clone, but seems 
immediately replaced later in `buildFromSorted`). Both should still be fine 
with this new return values.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24821#discussion_r2056616868

Reply via email to