EH in C (was: Re: (lack of) Thread-safe exceptions on AIX (gcc-2.95.1)

Zack Weinberg zack@wolery.cumb.org
Tue Feb 1 15:49:00 GMT 2000


On Tue, Feb 01, 2000 at 03:37:02PM -0800, Geoff Keating wrote:
> Zack Weinberg <zack@wolery.cumb.org> writes:
> 
> > The usual reason people want exceptions in C is to make pthread
> > cancellation play nice with C++.  The pthread library has 'cleanups'
> > that happen when a thread is cancelled, that are basically
> > try/finally, but they don't interoperate with the C++ exception
> > mechanism.  What you'd like is for pthread_cleanup_push/pop to be
> > implemented in terms of try/catch, and pthread_cancel to throw an
> > exception in the cancelled thread.
> > 
> > That requires only try { } catch (...) { }, plus some way to throw
> > an object (not just rethrow), in C.
> 
> Is there some reason why pthread_cleanup_push/pop can't be implemented
> in C++ (with 'extern "C"', of course)?

I don't think that would help any.  The effect of pthread_cleanup_push
is that if your thread is cancelled between it and the matching
pthread_cleanup_pop, the handler you specified gets called.  To make
that work with the exceptions mechanism, the code in between has to be
exception aware too.

zw


More information about the Gcc mailing list