This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin 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: dtors run twice on dll detach (update)


Hi Robert,


"Robert Collins" <robert.collins@itdomain.com.au> writes:
> > If we just avoid setting up the destructor calls using atexit 
> > then the destructors will only run once.  So, in the normal 
> > case, the destructor will run after much cleanup has occurred 
> > in the cygwin DLL (specifically in the do_exit function).  
> > This means that the destructor may not be able to use all of 
> > the facilities of cygwin when it is finally executed.
> 
> Yup. That is why I don't think that the atexit call is obsolete.
>  
> > This won't be an issue for the problem below, but I wonder if 
> > it is a problem for other destructors.  I'm not sure what 
> > kind of environment a global destructor is guaranteed to have 
> > but I suspect that it should be a completely normal environment.
> > 
> > Anyone know for sure?  Is there an online reference for this 
> > kind of thing?
> 
> It'll be in the C++ standard, which is proprietary :[. Anyone here have
> the standard and care to check for us?

C++ 98 in one spot (3.6.3 Termination, para 3) says that atexit()
functions are called before destructors for objects created before
registration of the atexit() functions and after destruction of
objects created after registration.  IOW the order is as if destructor
calls are implemented as atexit() functions.

Later in the description of exit() (18.3 Start and Termination, para
8) this is repeated.  Actions of exit() are defined to be in this
order:

- atexit() functions and destructor calls.

- Flushing C streams. 

- Return to OS with exit code. 

Except for the addition of destructor calls, this is the same
definition as in the C standard, judging from my copy of the last C9x
draft.


so long, benny


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