(from: http://topic.csdn.net/u/20090313/10/4c200070-3037-420b-983c-3329555f141d.html)

 

 
  
  1.  Singleton* Singleton::instance() 
  2.  
  3. {  if (!s_instance)  
  4.  
  5.    { boost::mutex::unique_lock lock(your_mutex); //假设用boost的lock      
  6.  
  7.       if(!s_instance) { //双判断          
  8.  
  9.         s_instance = new Singleton;       
  10.  
  11.       }  
  12.  
  13.    } 
  14.  
  15.    return s_instance;  
  16.  
  17. }