This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: G++ and constructors


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]