
David Abrahams wrote:
"Peter Dimov" <pdimov@mmltd.net> writes:
Pedro LamarĂ£o wrote:
Shouldn't there be some sentry object then, with that "on_thread_exit()" thing called by the destructor?
If you allow an exception to escape from your thread function, the default behavior is for the runtime to call terminate(), so a missing on_thread_exit is the least of your worries. :-)
Well, let's not forget that terminate() is a form of orderly shutdown.
It's easier to move the on_thread_exit call to a destructor than to argue about the precise meaning of orderly shutdown, so that's what I've done. :-) Index: thread.cpp =================================================================== RCS file: /cvsroot/boost/boost/libs/thread/src/thread.cpp,v retrieving revision 1.22 diff -u -r1.22 thread.cpp --- thread.cpp 6 Jul 2006 13:45:13 -0000 1.22 +++ thread.cpp 6 Jul 2006 19:45:57 -0000 @@ -94,6 +94,18 @@ bool m_started; }; +#if defined(BOOST_HAS_WINTHREADS) + +struct on_thread_exit_guard +{ + ~on_thread_exit_guard() + { + on_thread_exit(); + } +}; + +#endif + } // unnamed namespace extern "C" { @@ -107,13 +119,16 @@ { // try { +#if defined(BOOST_HAS_WINTHREADS) + + on_thread_exit_guard guard; + +#endif + thread_param* p = static_cast<thread_param*>(param); boost::function0<void> threadfunc = p->m_threadfunc; p->started(); threadfunc(); -#if defined(BOOST_HAS_WINTHREADS) - on_thread_exit(); -#endif } // catch (...) // {