Request for review: Race conditions in java.nio.charset.Charset

Ulf Zibis Ulf.Zibis at gmx.de
Thu Oct 8 11:58:55 UTC 2009


Am 08.10.2009 12:59, David Holmes - Sun Microsystems schrieb:
> Hi Ulf,
>
> It's a memory model issue. The code is like this:
>
>      public String getName() {
>          if (name == null)
>             name = getName0();
>          return name;
>      }
>
> but in theory, accoridng to the JMM experts, it could act as if it 
> does this:
>
>   public String getName() {
>     String tmp1 = name; // sees null
>     String tmp2 = name; // sees non-null
>     if (tmp2 == null)
>       tmp1 = name = getName0();
>     return tmp1;
>   }
>
> imagine the temporaries are registers.

Oops, java programming is not simple as it looks like. Can you give me a 
link, where I can read more about that subject / JMM?
David, thanks for your explicit explanation.

-Ulf





More information about the core-libs-dev mailing list