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: Destructor never gets called.


Alexandre Oliva wrote:
> 
> On Jun 11, 2001, "Liu, Guangsheng" <guangsheng.liu@intel.com> wrote:
> 
> > pthread_exit() exits itself.  After all the threads exit (t1, t2,
> > main thread), I didn't see Class A's destructor being called.
> 
> pthread_exit() is not guaranteed to unwind the stack of the thread, so
> destructors aren't called.  It only calls cleanup handlers, but
> destructors of automatic objects aren't registered as such.  It's
> debatable whether they should.

I think they should not, by analogy to exit (which does not
unwind the stack although naturally it calls atexit functions).

The correct way to exit in a C++ program (or thread) is to
throw an ExitException object and catch it in either main
or the top-level function of the thread.

-- James Dennett


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