Re: [c++-pthreads] Re: thread-safety definition
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [c++-pthreads] Re: thread-safety definition



On Jan 12, 2004, at 11:35 AM, Ted Baker wrote:

This problem could be eliminated by specifying that cancellation
is a special case, that cannot be caught by catch(...), i.e., that
it can only be caught by a handler that names it explicitly, or that
it cannot be caught at all.

That was originally proposed, and it's a bad idea.  There's too much
code of the form
  catch(...) {
    do_some_partial_cleanup();
    throw;
  }
This is important, and it's recommended style.  Uncatchable
exceptions would be a major change in the C++ exception model.

This existing code does not rely on being able to catch thread
cancellation, since it was written with only normal exceptions in
mind.  It is precisely because existing code does no know about
cancellation that we are having this dicussion, I thought.

That's a fair point.  I suspect you're right that we'll be wasting our
time if we hope we can do something that will make C++ code that
doesn't  know about cancellations work correctly even in the
presence of multiple threads and cancellation.

The real question we should be asking ourselves is how invasive
the necessary modifications would be under whatever proposal
we're looking at. (Modifications both to the C++ standard and to user
code.)

I still think that uncatchable exceptions aren't the right answer. Think
about the scope of the modifications that would be required:
 1. To a good first approximation, all code that catches and rethrows
      exceptions, and that might be used in a cancellable thread, would
      have to be modified.   (The basis of my claim: if you have to do
      some cleanup whenever an exception passes through your code,
      you'll still have to do it for cancellations too.)
  1a. This isn't too different from saying that all code that catches
         exceptions will have to be modified.  Most code that catches
         an exception ends up rethrowing it.
   2. Now think about what kind of modification we're talking about.
       Again, to a good first approximation, cleanup is cleanup.  So
       the example I've give above would be rewritten:
       catch(...) {
         do_some_partial_cleanup();
         throw;
       }
       catch (CancellationException) {
         do_some_partial_cleanup();
         throw;
       }
      We don't really want that to become recommended C++ style,
      do we?

			--Matt