On 26.06.2013, at 7:31, Dmitry Nadezhin <dmitry.nadez...@gmail.com> wrote:

> We have two versions after private discussion with Aleksey.
> 
> BigInteger getRadixConversionCache(int radix, int exponent) {
>  BigInteger[][] pc = powerCache; // volatile read
>  BigInteger[] cacheLine = pc[radix];
>  if (exponent < cacheLine.length)
>      return cacheLine[exponent];
> 
>  int oldSize = cacheLine.length;
>  cacheLine = Arrays.copyOf(cacheLine, exponent + 1);
>  for (int i = oldSize; i < exponent + 1; i++)
>      cacheLine[i] = cacheLine[i - 1].square();
> 
>  pc = Arrays.copyOf(powerCache);
>  pc[radix] = cacheLine;
>  powerCache = pc; // volatile write, publish
>  return cacheLine[exponent];
> }

Thanks, I like this version a lot better. We could check for the existing 
cacheLine.length right before installing the new one, so the opportunity to 
overwrite larger cacheLine would be minimal, but I do think the probability of 
unlucky timing is very low, and the argument is moot :) Let's keep it simple.

-Aleksey.

Reply via email to