G++ and constructors
Ian Lance Taylor
iant@google.com
Thu Mar 8 17:16:00 GMT 2007
Daniel Lohmann <daniel.lohmann@informatik.uni-erlangen.de> writes:
> John Love-Jensen schrieb:
> > [...] Although you didn't ask for work-arounds, here's a work-around
> > that works
> > for GCC, but may not work in C++ in general*.
> > GCC uses threading protection for static objects.
> > So this variant of your routine, in GCC, should be thread safe:
> > ----------------------------------------------------------------------
> > myclass* myclass::init_instance() // private: static
> > {
> > return new myclass();
> > }
> > myclass* myclass::get_instance() // public: static
> > {
> > static myclass* instance = InitInstance();
> > return instance;
> > }
> > ----------------------------------------------------------------------
>
> *GCC* does the threading protection?
>
> I really wonder how!
>
> How can GCC achieve this on every platform (especially embedded
> targets such as AVR, H8, ARM) without help from the runtime? (I
> haven't seen any dependencies to RTL functions in such case.)
>
> Is this implemented using interruption-transparent algorithms / atomic
> operations or does the above simply hold only for some specific
> platform?
Processor specific details can be found in libstdc++-v3/config/cpu.
That code is used by the guard code in libstdc++-v3/libsupc++.
Ian
More information about the Gcc-help
mailing list