On 11/Dec/2009 04:09, Vijay Menon wrote:
> Perhaps I'm missing some context, but I don't see any problem. I don't
> believe that this:
>
> if (hashCode == 0) {
> // calculate hash
> hashCode = hash;
> }
> return hashCode;
>
> can ever return 0 (assuming hash is non-zero), regardless of memory fences.
> The JMM won't allow visible reordering in a single threaded program.
I agree. In the multi-threaded case there can be a data race on the
hashCode, with the effect that the same hashCode value is unnecessarily,
but harmlessly, recalculated.
Regards,
Tim