This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Destructor never gets called.
- To: "'Alexandre Oliva'" <aoliva at redhat dot com>
- Subject: RE: Destructor never gets called.
- From: "Liu, Guangsheng" <guangsheng dot liu at intel dot com>
- Date: Wed, 13 Jun 2001 10:14:23 -0400
- Cc: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
>> 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.
pthread_exit() should never call the destructor of global object.
As in this scenario, global object constructed before main(), then main()
thread
created 2 threads t1, t2, after that, main() thread call pthread_exit(). At
this
point, t1, t2 still alive, they may use this global object, therefore,
pthread_exit() in main thread should not destruct this global object.
I mean the "last thread" in the whole process should destruct this object
at its
exit point if it could. I really don't know how threads get implemented in
RedHat
Linux. However, I do know when thread is created from main thread, it
generates
"additional thread". I guess this additional thread may manage the all the
threads
in the process somehow, maybe it should destruct the object there. ......
Guangsheng Liu