global {con,de}structors, atexit & friends
Martin von Loewis
martin@mira.isdn.cs.tu-berlin.de
Sat Jul 25 09:14:00 GMT 1998
> - 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
More information about the Gcc
mailing list