|
Boost : |
From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-08-11 18:35:20
It's such an vacuous technicality to base anything on not being able to call
main. You imply that
1) C++ provides extra functionality for functions that the end user is
allowed to define but not legally allowed to call
2) this functionality was likely inherited from C
3) main is one of these special functions
I don't think so.
The only thing demonstrated by your statement is that the C++ language
likely suspects main as the only entry point, but it has already been said
over and over that C++ is not inherently multi-threaded.
It's just one more reason why main () should be hidden from the developer in
multi-threaded C++ because it introduces a duality that causes the issues
you've graciously pointed out.
----- Original Message -----
From: William Kempf
Newsgroups: gmane.comp.lib.boost.devel
Sent: Sunday, 2002:August:11 6:30 PM
Subject: Re: Re: Re: Threads & Exceptions
>From: "Victor A. Wagner, Jr." <vawjr_at_[hidden]>
>Reply-To: boost_at_[hidden]
>To: boost_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)
>>{
>> try
>> {
>> pthread->join();
>> }
>> catch(...)
>> {
>> cout << "main() threw an exception" << endl;
>> }
>> delete pthread;
>>}
>>
>>int main()
>>{
>> 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
>seems irrelevant.
>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.
>#include "stdafx.h"
>#include <iostream>
>#include <string>
>#include <iomanip>
>#include <boost/lexical_cast.hpp>
>
>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 <<
>endl;
> try
> {
> 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: " +
>boost::lexical_cast<string>(argc)).c_str());
> }
> 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.
Bill Kempf
williamkempf_at_[hidden]
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk