2
Replacing with a higher-level abstraction:
• Singleton* instance;
• Singleton* GetInstance() {
  once {
      instance = new T;
  }
  return instance;
}
And allowing this variant:
• Singleton* instance = new T;
• Singleton* GetInstance() {
  return instance;
}
•Variables should only be initialized once, so we should require the compiler to implicitly Do the Right Thing.
Example: Double-Checked Locking (DCL).
• volatile Singleton* instance;
• Singleton* GetInstance() {
  if( !instance ) {
    // acquire lock
    if( !instance ) {
      instance = new T;
    }
    // release lock
  }
  return instance;
}
•Works on some platforms (including VC++ 2005).
Read the manual carefully.
•Error-prone. Omit volatile, program compiles & “works.”
•Too low-level. Like coding your own vtables…
Illustrating a Principle: Codifying Idioms