Boost logo

Boost :

From: terekhov (terekhov_at_[hidden])
Date: 2002-01-14 16:41:53


--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
>
> ----- Original Message -----
>
> This part made no sense to me:
>
> <<From: "terekhov" <terekhov_at_d...>
> Anyway, that was a WRONG solution! catch(...)/
> cancellation/exit is a moot point, I think.
> I just rushed in without too much thinking and
> should not have done it in the first place because
> a) auto_rethrow_exception() just breaks catch(...)
> without throw; semantics and b) thread cancel/exit
> should NOT be caught without throw; (or
> program termination) at all!! Look, you could
> always control cancellation (using cancel state
> and type) and thread exit exception could carry
> not so smart objects (to return to joiner(s))
> which could result in resource leaks catching
> it without throw; or program termination. Such
> code is simply broken! It is just a breach of
> contract, I think.>>

// Resource leaks and violation of cancel/exit contract
try {

  pthread_testcancel();
  //...
  pthread_exit( new result() );

}
catch( pthread_cancel_e& thread_cancel_e ) {

 cout << "Someone called pthread_cancel() on me and it worked, but I
do not care" << endl;

}
catch( pthread_exit_e& thread_exit_e ) {

 cout << "Someone inside try block decided to end this thread with
pthread_exit(), but I do not care" << endl;

}

// OK code
try {

  pthread_testcancel();
  //...
  pthread_exit( new result() );

}
catch( pthread_cancel_e& thread_cancel_e ) {

 cout << "Someone called pthread_cancel() on me and it worked, that
is good" << endl;

 throw;

}
catch( pthread_exit_e& thread_exit_e ) {

 cout << "Someone inside try block decided to end this thread with
pthread_exit(), that is OK" << endl;

 throw;

}

// OK code
try {

  pthread_testcancel();
  //...
  pthread_exit( new result() );

}
catch( ... ) {

  throw;

}

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk