This is the mail archive of the gcc@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]

Re: global {con,de}structors, atexit & friends


> - do you agree?
> - do we miss something?

As I said before, I like this. After thinking about it, I feel you
miss some points:
- The __DYNAMIC_DTOR_LIST__, is it per shared object, or global (per
  process). If per shared object (i.e. one for each shared library),
  how do you handle the interleaving of destructors across shared
  objects? I.e.

  void f(){  //a.so
    static A x;
  }

  void g(){  //b.so
    static B x;
    f();
    static B y;
  }

  This could be solved by making the DTOR_LIST a list and not an
  array. Of course, inserting an element in the front of the chain
  is more expensive in a MT environment.

- How do you handle static objects initialized during global
  constructors? I.e

  void f();
  struct A{
    A(bool b){
      if(b)f();
    }
    ~A(){side_effects();}
  };
  A global(true);
  void f(){
    static A lokal(false);
  }
  A another(false);

To solve this, even the globals would need slots in .dtor.dynamic.

Martin


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