|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
Re: at_thread_exit() never getting called"vicente.botet" <vicente.botet@...> writes:
>>> cowwoc wrote: >>>> I am registering boost::this_thread::at_thread_exit() against one of my >>>> threads. When the main thread exits using "return 0" the at_thread_exit >>>> hook >>>> never gets invoked. Is this normal? If you call exit() then thread exit handlers are not called. "return 0" in main() is the same as calling exit(0), so thread exit handlers are not called. > Anthony, I've see that you have started to integrate the patch for the > thread attributes. Do you plan to integrate this patch also? No. 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. Anthony -- Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976 _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost |
|
|
Re: [Boost-users] at_thread_exit() never getting calledHi,
----- Original Message ----- From: "Anthony Williams" <anthony.ajw@...> To: <boost-users@...> Cc: <boost@...> Sent: Thursday, October 29, 2009 9:49 AM Subject: Re: [Boost-users] at_thread_exit() never getting called > > "vicente.botet" <vicente.botet@...> writes: > >>>> cowwoc wrote: >>>>> I am registering boost::this_thread::at_thread_exit() against one of my >>>>> threads. When the main thread exits using "return 0" the at_thread_exit >>>>> hook >>>>> never gets invoked. Is this normal? > > If you call exit() then thread exit handlers are not called. "return 0" > in main() is the same as calling exit(0), so thread exit handlers are > not called. > >> Anthony, I've see that you have started to integrate the patch for the >> thread attributes. Do you plan to integrate this patch also? > > No. > > 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. 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. Do you think that we need a portable function boost::exit that will call to pthread_exit? 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. Do you have a portable solution? Best, Vicente _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost |
|
|
Re: at_thread_exit() never getting called"vicente.botet" <vicente.botet@...> writes:
> From: "Anthony Williams" <anthony.ajw@...> >> 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. Anthony -- Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976 _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost |
|
|
Re: at_thread_exit() never getting called----- Original Message ----- From: "Anthony Williams" <anthony.ajw@...> To: <boost@...> Cc: <boost-users@...> Sent: Thursday, October 29, 2009 2:54 PM Subject: Re: [boost] at_thread_exit() never getting called > > "vicente.botet" <vicente.botet@...> writes: > >> From: "Anthony Williams" <anthony.ajw@...> >>> 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 _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost |
| Free embeddable forum powered by Nabble | Forum Help |