Re: atomically thread-safe Meyers singleton impl (fixed)...
On Jul 30, 6:44 am, "Chris Thomasson" <x...@xxx.xxx> wrote:
[...]
Any thoughts on this approach?
I'm not familiar enough with modern the x86 architecture and
VC++'s implementation of it to judge, but my first reaction is,
why bother? It's fairly easy to ensure (in practice) that the
first initialization of the singleton occurs either before main
(and thus, hopefully, before threads have started), or in a
protected environment (during dynamic loading, before the loaded
memory is made visible to threads other than the one doing the
loading). It's also fairly easy to fusion the mutex lock with
any mutex lock needed to use the singleton (so its effective
cost is 0). And of course, acquiring a mutex lock when there is
no contention is very, very fast anyway.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34