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.


>> 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

  


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