It’s worth noting that not only do you need to synchronize access to the singleton, you need to synchronize access to the singleton’s state as well. And even if you manage that at a fine-grained layer, you’re still setting yourself up for all the problems associated with singletons: http://c2.com/cgi/wiki?SingletonsAreEvil.If you have a bunch of immutable state, then build unexported package variables in the package’s `init` func and export funcs which use those variables.
If you have a bunch of mutable state, then don’t use a singleton.
lemevi|10 years ago
codahale|10 years ago
The code you write is either thread-safe, used in a single-threaded context, or a pinless grenade.
doomrobo|10 years ago
eloff|10 years ago