[concurrency-interest] DCL clarification Immutable singelton

vikas vikas.vksingh at gmail.com
Thu Apr 10 10:10:37 EDT 2014

But is the same benign data race thing can be applied to DCL.
i.e is the code below DCL with a temp variable and immutable Singleton, can
return null? Is there a possible reordering which will allow the below code
to return null. 

final class  Singleton { 

          private static  Singleton _instance;  // not a volatile variable 

          public static Singleton getInstance() { 
                            Singeltom temp = _instance;  
                            if(temp == null) { 
                                       synchronized(Singleton.class) { 
                                                 temp = _instance; 
                                                 if(temp == null) { 
                                                       _instance =temp = new
                            return temp; 
          private Singleton() { 
          *final* private int i,j,k;               

View this message in context: http://jsr166-concurrency.10961.n7.nabble.com/DCL-clarification-Immutable-singelton-tp10862p10878.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.

More information about the Concurrency-interest mailing list