Use of volatile : Lock : Thread C# Examples


C# Examples » Thread » Lock »

 

Use of volatile









    
using  System;

class  Singleton
{
        static  object  sync  =  new  object();
        
        static  volatile  Singleton  singleton  =  null;
        
        private  Singleton()
        {
        }
        
        public  static  Singleton  GetSingleton()        
        {
                if  (singleton  ==  null)
                {
                        lock(sync)
                        {
                                if  (singleton  ==  null)
                                singleton  =  new  Singleton();
                        }
                }
                
                return(singleton);
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Thread
» Lock