On 11/15/16 3:05 PM, Kapps wrote:
Keep in mind, this is only slow for such a large amount of calls.
If you're calling this only a hundred times a second, then who cares if
it's slower. After all, with GDC we were looking at 1 billion calls in
21 seconds. That's 47,000 calls per *millisecond*.
This is the wrong way to look at it.
If you are calling it from one thread, then 100 times/second is no
problem. If you have 100 threads calling it 100 times a second, you have
killed any performance gained by using threads in the first place.
The reason lock-free singletons are so attractive is because of the
allowance of multiple threads to use it at the same time without
contention. It's why years of "slightly wrong" advice on singletons has
been out there, and why this solution is so amazing in its simplicity.
-Steve