pthread_cancel and EH: let's try this again

David Abrahams dave at boost-consulting.com
Wed Jul 13 16:27:45 UTC 2005


Nathan Sidwell <nathan at codesourcery.com> writes:

Nathan Sidwell <nathan at codesourcery.com> writes:

> Jason Merrill wrote:
>> OK, let me clarify my position.  For a new C++ threading library, I would
>> continue to prefer scheme #1.  But this isn't a new library, it's an
>> extension of an existing library.
>
> thanks for this rationale.  I better understand the problem that needs to be 
> solved now.
>
>> Compatibility with existing pthreads code is more important than
>> consistency with C++ exceptions.
>
> Another point of interest, which I'm sure you've considered, is that standard C 
> functions such as write are deemed to be nothrow by C++, yet are cancellation 
> points in pthreads.  Scheme #2 stops this blowing up (by deferring cancellation 
> inside such function).  Scheme #1 blows up by calling std::unexpected.

One way to look at it is that scheme #1 blows up, true.  But not
necessarily by calling std::unexpected.  Those functions do not
implicitly acquire an empty exception-specification -- they are simply
required not to throw.  If they start throwing, they break user code
by violating its expectations.

A more correct way to look at it, IMO, is that an implementation of
C++ that throws from standard 'C' functions by default (other than
when the user does something documented to cause undefined behavior)
is nonconforming to the C++ standard.  In other words, those functions
simply can't throw in C++, at least not without explicitly being given
permission by the program.  I would:

  0. Continue to forbid those functions to throw in C++, to preserve
     conformance

  1. Add a non-throwing mechanism to report cancellation from those
     functions, such as extended values of errno.

  2. Optional: As an extension, provide a parallel set of functions
     (in a namespace other than :: or std:: ) that can throw.

  3. Optional: As an extension, provide a way to enable the normal 'C'
     library to throw cancellation

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




More information about the c++-pthreads mailing list