[basic-improvements] try/finally support for c/c++ - more tests

Geoff Keating geoffk@geoffk.org
Thu Nov 7 12:18:00 GMT 2002


Mark Mitchell <mark@codesourcery.com> writes:

> We're trying to implement one particular piece of functionality required
> by the POSIX threads interface; namely "pthread_cleanup_push" and friends.
> (I know that any feature might get used more widely, but this is the
> motivation, as I understand it.)  Furthermore, we're trying to make the
> POSIX threads cleanups play nice with exception-handling.

Yes, this is right, but your example is not the case we really care
about.  What we particularly want to make work is this C++ code:

struct A { ~A() { ... } };

{
  A foo;
  sigpause ();  // cancellation point, I hope
}

Here, if 'sigpause' gets cancelled, we want A's destructor to not be
run.  At present, cancellation is implemented using setjmp/longjmp,
and so knows nothing about C++ destructors, and so this doesn't work.
If we made C++ use setjmp/longjmp for destructors, that would be very
expensive for all C++ code.  Instead, we want to make cancellation use
the C++ exception mechanism, because that's already there and so
wouldn't impose any extra overhead on C++ code.  The problem is that
then we can't implement pthread_cleanup_push in C, because C can't
interact with the exception mechanism.

-- 
- Geoffrey Keating <geoffk@geoffk.org>



More information about the Gcc-patches mailing list