On 06/27/2013 10:37 AM, Peter Levart wrote: > Hi, > > This version seems correct. Maybe just replace double volatile read at > length re-check with a single one: > > > private static BigInteger getRadixConversionCache(int radix, int > exponent) { > BigInteger[] cacheLine = powerCache[radix]; // volatile read > if (exponent < cacheLine.length) > return cacheLine[exponent]; > > int oldLength = cacheLine.length; > cacheLine = Arrays.copyOf(cacheLine, exponent + 1); > for (int i = oldLength; i <= exponent; i++) > cacheLine[i] = cacheLine[i - 1].pow(2); > > BigInteger[][] pc = powerCache; // volatile read again > if (exponent >= pc[radix].length) { > pc = pc.clone(); > pc[radix] = cacheLine; > powerCache = pc; // volatile write, publish > } > return cacheLine[exponent]; > } >
Yes, I'm voting for this one. All other improvements Peter had suggested, while interesting, seem to not to worth the trouble. -Aleksey.