On Friday, 31 January 2014 at 10:57:53 UTC, Andrej Mitrovic wrote:

The atomic implementation probably beats the TLS version when a lot of
new threads are being spawned at once and they only retrieve the
singleton which has already been initialized. E.g., say a 1000 threads
are spawned.

Easy enough to test. But inconclusive. I just ran some tests with 1024 threads :)

First, subsequent runs on my machine show interleaving results:

Test time for SyncSingleton: 61.2334 msecs.
Test time for AtomicSingleton: 15.9795 msecs.

Test time for SyncSingleton: 11.209 msecs.
Test time for AtomicSingleton: 25.4395 msecs.

Test time for SyncSingleton: 22.8105 msecs.
Test time for AtomicSingleton: 35.1865 msecs.

I guess I'd need a different CPU (and probably one that's not doing anything else at the time) to get conclusive results.

It also seems that either there *is* a race in there somewhere, or maybe a bug?.. Some runs just flat freeze (even on small thread counts) :\

Reply via email to