|
Boost : |
Subject: Re: [boost] at_thread_exit() never getting called
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-10-29 11:22:54
----- Original Message -----
From: "Anthony Williams" <anthony.ajw_at_[hidden]>
To: <boost_at_[hidden]>
Cc: <boost-users_at_[hidden]>
Sent: Thursday, October 29, 2009 2:54 PM
Subject: Re: [boost] at_thread_exit() never getting called
>
> "vicente.botet" <vicente.botet_at_[hidden]> writes:
>
>> From: "Anthony Williams" <anthony.ajw_at_[hidden]>
>>> If you call pthread_exit(0) from main() then thread exit handlers *will*
>>> be called. Of course, this doesn't exit the program until all other
>>> threads have terminated, whereas "return 0" kills the other threads.
>>
>> Unfortunately, after rereading the patch I proposed, I recognize the
>> patch don't works if there are other external threads in the programm
>> as in patch stores only the last external thread context.
>
> Yes. That's one reason I didn't apply it.
>
>> Calling pthread_exit(0) on a pthread thread is natural, but the main
>> thread is no created as a pthread, so this call is not portable.
>
> True; it's only portable among POSIX platforms, which sort-of defeats
> the point of using boost.
>
>> Do
>> you think that we need a portable function boost::exit that will call
>> to pthread_exit?
>
> This is tricky. pthread_exit() and it's Windows counterpart ExitThread
> abrubtly end the thread when called, without unwinding the stack. In
> C++, we probably want the stack to unwind, in order for all our nice
> RAII objects to release their resources.
>
>> With the current implementation we don't have any error when we call
>> at_thread_exit on an external thread. This has as consequence that the
>> destructors of the TSS are not called. This is a severe restriction
>> from my point of view.
>
> at_thread_exit works on every thread: the cleanup runs when the thread
> exits "normally". If you call exit() then cleanup functions are not
> run. The problem is that returning from main() is equivalent to calling
> exit() (and thus skips the cleanup), whereas returning from any other
> thread function just exits that thread (and does the cleanup).
>
>> Do you have a portable solution?
>
> Don't do any work in main(): spawn a new thread and have main() wait for
> it.
OK, I see. Please could you add this resolution to the ticket and add a warning and this guideline to the Boost.Thread documentation?
Thanks,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk