Re: G++ and constructors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?


Daniel

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux