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

David Abrahams dave at boost-consulting.com
Tue Jul 12 00:50:20 UTC 2005


Jakub Jelinek <jakub at redhat.com> writes:

> On Mon, Jul 11, 2005 at 06:34:13PM -0400, David Abrahams wrote:
>> Nathan Sidwell <nathan at codesourcery.com> writes:
>> 
>> > IMHO #1 is better, for it also allows us to say 'thread cancellation is
>> > *exactly* like exception handling'.
>> 
>> It's more than that.  #2 changes the exception handling model.
>> Simplicity of definition and programming model is crucial.  People
>> already have enough trouble coming to grips with exception safety.
>> Introducing #2 complicates the EH model, so I oppose it on those
>> grounds also.
>
> Can you explain why?  Nothing says that what pthread_cancel does is throwing
> an exception.  So what exactly it does is outside of the scope of the
> current C++ standard.

Of course it's outside of the scope of the current C++ standard, but I
don't see how that's relevant.  All the proposals in this thread have
pthread_cancel throwing an exception.

The mental model one develops for exception handling based on standard
C++ includes invariants such as

    catch(...) { whatever; throw; }  

  is equivalent to 

    a destructor that does "whatever" when unwinding


and

    If a destructor executes due to stack unwinding, one catch block
    of every try block between the point of the throw and that
    destructor has executed.

These invariants no longer hold in scheme #2.  You get something sort
of like these invariants, but they are complicated by special cases to
deal with thread cancellation behavior.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com



More information about the c++-pthreads mailing list