From: William Kempf (williamkempf_at_[hidden])
Date: 2002-08-11 17:30:55
>From: "Victor A. Wagner, Jr." <vawjr_at_[hidden]>
>Subject: Re: [boost] Re: Re: Threads & Exceptions
>Date: Sun, 11 Aug 2002 11:59:15 -0700
>At Sunday 2002/08/11 06:48, you wrote:
>>>From: "Victor A. Wagner, Jr." <vawjr_at_[hidden]>
>>>At Thursday 2002/08/08 07:49, you wrote:
>>>>----- Original Message -----
>>>>From: "Victor A. Wagner, Jr." <vawjr_at_[hidden]>
>>void my_thread(boost::thread* pthread)
>> cout << "main() threw an exception" << endl;
>> delete pthread;
>> boost::thread* main = new thread();
>> boost::thread thrd(boost::bind(&my_thread, main));
>> thread_exit(); // Yes, this is something that needs added to
>> // Boost.Threads, and will be.
>> throw "error!";
>>The above can't be done portably, AFAIK, and is likely to result in
>>termination instead of the expected passage in join().
>I have no idea what this is supposed to "do" so that it's not portable
>Although I have no idea what thread_exit() will actually do, having it
>execute the next line of code seems counter-intuitive.
>The following code works as I expected on VC++.NET (not that I'm attempting
>to hold it out as either definitive nor conforming) and if the "if (argc >
>2)" is removed or changed to, say, >1, the "unexpected exception" occurs,
>otherwise this executes to completion without "problem".
Shoot. My apologies. I wrote that way too fast. The throw should have
occured before the call to thread_exit(). The point being that, as per
behavior on every platform I'm familiar, thread_exit() (i.e. its platform
equivalent) causes the thread to exit, and in the case of the main thread
this means the process doesn't terminate until all other threads complete.
The throw skips the call to thread_exit(), and thus the terminate() is
called because of the uncaught exception. This means the main thread
behaves differently from all other threads with regard to exception
handling... unless you 1) can change the language rules or 2) make the
exception handling consistent by having threads call terminate() in case
there's an uncaught exception as well.
>using namespace std;
>int main(int argc, char* argv)
> cout << setw(2*argc) << ' ' << "entering main: " << argc << endl;
> if (++argc < 10)
> cout << setw(2*argc) << ' ' << "calling main: " << argc <<
> main(argc, 0);
Results in undefined behavior. You're not allowed to call main(). Anything
that happens next means nothing.
> catch (exception& e)
> cout << setw(2*argc) << ' ' << "exception: " <<
>argc << " " << e.what() << endl;
> cout << setw(2*argc) << ' ' << "returned from main: " <<
>argc << endl;
> if (argc > 2)
> throw exception(("throwing: " +
> cout << setw(2*argc) << ' ' << "returning: " << argc << endl;
I'm not sure what you were trying to illustrate with this code... but the
use of illegal C++ would seem to make anything you observe irrelavant.
Send and receive Hotmail on your mobile device: http://mobile.msn.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk