[c++-pthreads] Re: pthread_cancel and EH: let's try this again

Mark Mitchell mark at codesourcery.com
Fri Jul 15 07:53:40 UTC 2005


Jakub Jelinek wrote:

> I wouldn't say that.  NPTL simply requires that class destructors
> are run during cancellation's forced unwinding.  I don't see why it would
> imply something about catch (...) though, it still doesn't mean cancellation
> is an exception, just that some mechanism runs the class destructors.

It's not NPTL that says something about "catch (...)" -- it's C++ that 
says that.

The whole point of destructors and exceptions in C++ is that you are 
guaranteed that all exits from a block will result in a particular set 
of cleanup code -- including both destructors and the bodies of catch 
clauses -- being run in a particular order.

Jason's proposal #2 splits two things which are considered equivalent by 
programmers (destructors and catch clauses) into distinct classes, 
running some but not the other.  That's not in the spirit of C++, IMO. 
  As Nathan has demonstrated, there are cases where you *must* use a 
catch clause to manage cleanups.

The justification for approach #2 is compatibility with the POSIX C 
bindings -- but real compatibility would be not to run any cleanup code 
at all, not to run some cleanup code, but not all of it.

If it's not technically feasible to avoid running destructors other than 
those for the magic pthread cleanup class, then the only palatable 
solution is to run all cleanup code, including "catch(...)" clauses.

-- 
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery.com
(916) 791-8304



More information about the c++-pthreads mailing list