[c++-pthreads] Re: FW: RE: Re: I'm Lost

Jason Merrill jason at redhat.com
Wed Mar 8 23:08:48 UTC 2006


Mark Mitchell wrote:
> Wil Evers wrote:
> 
>> So who/where is this alledged "other side"? 
> 
> IIRC, Jason Merill has also historically been sympathetic to the forced
> exception mechanism, because (if I paraphrase correctly!) he feels that
> it might help some code move into a threaded environment without change.
>  In particular, by ignoring "catch" handlers, some subset of real
> programs might behave well enough, in that destructors would run to
> clean things up, and the code wouldn't have to be modified to know about
> thread-cancellation exceptions.

Yes.  This is the choice that Ada made for handling task cancellation; 
it functions like an exception except that it cannot be caught, at least 
not by user code.

 > However, again, if I recall correctly,
> Jason was also OK with the idea that a thread could catch a cancellation
> exception, but that future calls to cancellation points would cause it
> to be re-canceled.

Yes.  Cancellation is not just an indication of a problem like most 
exceptions, it's specifically an attempt to unwind everything.  There is 
a lot of code out there that does catch (...), tries to do generic 
recovery, and continue.  iostreams does catch (...) and sets a flag 
instead of propagating an exception.  Neither of these situations should 
cause the cancel to be discarded.

Both the Ada approach and the re-cancellation approach avoid this 
problem of accidentally losing the cancellation request.

If you can interrupt cancellation, re-cancellation is implemented 
trivially simply by just having the cancellation exception destructor 
call 'pthread_cancel (pthread_self ())'.  The sticking point is being 
able to abort the cancellation in the first place, which is what Uli has 
been opposed to.

> As far as I remember, Ulrich is the only person who has really argued
> that it is unambiguously wrong to consider the situation in which a
> thread catches a cancellation exception.

I don't think he's opposed to catching it, just to doing anything that 
would involve backing out of the cancellation once it's started.

Jason



More information about the c++-pthreads mailing list