Re: atomically thread-safe Meyers singleton impl (fixed)...
On Jul 30, 11:56 am, "Chris M. Thomasson" <n...@spam.invalid> wrote:
"Dmitriy V'jukov" <dvyu...@gmail.com> wrote in message
news:e9e8900f-0031-4d0f-beda-> 98d4b43be...@k37g2000hsf.googlegroups.com.=
...
On 30 =C9=C0=CC, 12:59, James Kanze <james.ka...@gmail.com> wrote:
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)
For example this way :)
http://groups.google.ru/group/comp.lang.c++.moderated/msg/e6c403a4316...
YES! However, there might be some retarded program which
spawns threads in a singleton before main is called. Hence, my
contrived band-aid...
It's not necessarily retarded, depending on what the library
which does so is doing. But such a program either 1) knows
about the singleton, and its constraints, and will ensure that
it is constructed before starting the thread (e.g. by calling
Singleton::instance() before calling pthread_create), or it
doesn't know about the singleton, and in such cases, it won't
use it in the spawned threads.
The case seems constrained enough that I wouldn't worry about
it.
--
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