Skip to content

Commit 6dc4edb

Browse files
committed
bugfix: clear must use writeLock
1 parent 02286a3 commit 6dc4edb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/java/com/trivago/fastutilconcurrentwrapper/map/PrimitiveConcurrentMap.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ protected PrimitiveConcurrentMap(int numBuckets) {
2323
locks[i] = new ReentrantReadWriteLock();
2424
}
2525

26+
/** Lock must be held! */
2627
protected abstract Function<K,V> mapAt (int index);
2728

2829
@Override
@@ -59,12 +60,12 @@ public boolean isEmpty () {
5960
@Override
6061
public void clear () {
6162
for (int i = 0; i < numBuckets; i++) {
62-
Lock readLock = locks[i].readLock();
63-
readLock.lock();
63+
Lock lock = locks[i].writeLock();
64+
lock.lock();
6465
try {
6566
mapAt(i).clear();
6667
} finally {
67-
readLock.unlock();
68+
lock.unlock();
6869
}
6970
}
7071
}

0 commit comments

Comments
 (0)