You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I spent some time debugging the locking mechanism in the ReentrantReadWriteLock and HTreeMap classes to see what was going on. Particularly this piece of code here:
private inline fun <E> segmentWrite(segment:Int, body:()->E):E{
val lock = locks[segment]?.writeLock()
lock?.lock()
try {
return body()
}finally{
lock?.unlock()
}
}
I filed this as a bug because I encountered this very strange case upon calling remove(key) while doing a for-each in the map. The READ lock is blocking the remove operation and stays stuck forever. You can see here what's going on:
However, I think your implementation should check for the READ lock and throw a similar java.util.ConcurrentModificationException in this case, to avoid forever-locking issues like these.
The text was updated successfully, but these errors were encountered:
I spend a bit of time debugging this simple case.
It's a very simple use case:
I spent some time debugging the locking mechanism in the
ReentrantReadWriteLock
andHTreeMap
classes to see what was going on. Particularly this piece of code here:I filed this as a bug because I encountered this very strange case upon calling
remove(key)
while doing a for-each in the map. The READ lock is blocking the remove operation and stays stuck forever. You can see here what's going on:After a quick google search, I realized this kind of operation is illegal and that's why you must use an iterator to do this: https://stackoverflow.com/questions/6092642/how-to-remove-a-key-from-hashmap-while-iterating-over-it
However, I think your implementation should check for the READ lock and throw a similar
java.util.ConcurrentModificationException
in this case, to avoid forever-locking issues like these.The text was updated successfully, but these errors were encountered: