why the last thread must sweep to check every slot again?
Liu via Concurrency-interest <[email protected]> Thu, 16 Jul 2020 20:01:38 +0800
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <[email protected]> |
hello concurrency-interest: In jdk1.8, ConcurrentHashMap's transfer function is used to resize, but there is a place I don’t understand. see below.
if (i < 0 || i >= n || i + n >= nextn) {
int sc;
if (finishing) {
nextTable = null;
table = nextTab;
sizeCtl = (n << 1) - (n >>> 1);
return;
}
if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, sc - 1)) {
if ((sc - 2) != resizeStamp(n) << RESIZE_STAMP_SHIFT)
return;
finishing = advance = true;
i = n; // recheck before commit
}
}
From the code above, the last thread to restore sizeCtl must recheck every slot again. But in my opinion, when the last thread to restore sizeCtl, every slot have been transfer to the new table already. So why why the last thread must sweep to check every slot again?
_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest