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.
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.
The code you write is either thread-safe, used in a single-threaded context, or a pinless grenade.
My favorite is the libdispatch abuse of cpuid to flood the pipeline on Intel CPUs for this problem: https://www.mikeash.com/pyblog/friday-qa-2014-06-06-secrets-...
But really, take Coda's advice. If you aren't synchronizing your reads, you can basically just assume your code is broken.
https://en.m.wikipedia.org/wiki/Lamport%27s_bakery_algorithm
Thread safety without synchronisation primitives. I'm not sure it's ever actually a good idea to use it, though.
EDIT: unless you count a fence as a synchronisation primitive.