9 December 2011

Links on the singleton pattern

I'd been going to interviews over the past month and the singleton is still the most popular point of discussion. I would try to bring up other patters (let's discuss the visitor!) but to no avail. It's popular beyond its usefullness, and so I just hate discussions on it. However, it did force me to dredge up memories of discussions on the difficulties in managing the lifetime of a singleton in C++. The links:

  • To Kill a Singleton John Vlissides' detailed analysis of the problem and possible solutions
  • Double-checked locking - I'm embarrassed to say that I'd never heard of this (though may have used a form of it before). Check the singleton for construction and grab a lock if it needs constructed. Once getting the lock on an object, you have to re-verify that it needs constructed since it could have happened while you were obtaining the lock. Neat.
  • Once Is Not Enough - Jim Hyslop and Herb Sutter's discussion on the similarities/differences of singletons and global variables
[ posted by sstrader on 9 December 2011 at 9:19:50 AM in Programming ]