[concurrency-interest] Explicitly initializing volatile fields with default values

Justin Sampson jsampson at guidewire.com
Thu Dec 17 21:11:24 EST 2015

Doug Lea wrote:

> Yes. Without a machine-checkable JLS and JMM formalization, it's
> hard to prove this definitively. But your account is a more
> careful version of reasoning we've done before to conclude that
> there is never any reason to explicitly initialize fields to
> 0/0.0/false/null. (There might be traces of these discussions in
> the original JSR133 mail archives.)

This seems like a specific instance of the more general question of
whether _any_ volatile write has visible memory ordering effects if
it doesn't actually change the value stored in memory. I remember a
discussion touching on that question back in January regarding the
semantics of a failed or no-op compareAndSet. Since the value is not
changed, there is no way for another thread to notice that anything
has happened, and therefore no other thread can _depend_ on any such
memory ordering effects for correctness -- at least in practical
terms, even if some specific executions happen to be ruled out.

That thread was "Varieties of CAS semantics" here:



More information about the Concurrency-interest mailing list