This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: G++ and constructors
- From: Ian Lance Taylor <iant at google dot com>
- To: Daniel Lohmann <daniel dot lohmann at informatik dot uni-erlangen dot de>
- Cc: John Love-Jensen <eljay at adobe dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: 08 Mar 2007 09:12:01 -0800
- Subject: Re: G++ and constructors
- References: <C212BE33.1D26D%eljay@adobe.com> <45EEE953.3090409@informatik.uni-erlangen.de>
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