On Feb 20, 2014, at 12:09 PM, David Holmes <david.hol...@oracle.com> wrote:

> If the sentinel values were the default zero values there would be no issue

This is an instance of the "stable value" pattern; see the javadoc for 
java/lang/invoke/Stable.

Using zero for the sentinel in this pattern is the safest option.

If I'm reading the JMM argument right, using a non-default value (perhaps even 
an explicitly set zero value) relies on accidental effects from nearby final 
variables, which is fragile even if correct on HotSpot or in a future JMM.

If zero is also a valid result, and the "+1" values everywhere are odious, make 
a wrapper method that returns the corrected value, and applies the correction 
in just one place.  That is much preferable to risking an initial race 
condition on your stable value.

— John

Reply via email to