[concurrency-interest] Potential data race in java.util.concurrent.ConcurrentHashMap at the fields TreeNode.left and right

Kasper Nielsen kasperni at gmail.com
Thu Mar 26 04:35:34 EDT 2020


> I think there is a data race in the class java.util.concurrent.ConcurrentHashMap.
> When reading from the fields TreeNode.left and TreeNode.right using get and writing to those fields using put those fields are not synchronized.
> I think they both should be volatile similar to the field next of the class Node.

All the fields in TreeNode are only read/written while synchronizing
on the TreeBin they belong to.
See, for example,
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java?revision=1.323&view=markup#l1902

Normal

/Kasper


More information about the Concurrency-interest mailing list