This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __attribute__((cleanup(function)) versus try/finally
On Thu, 2003-05-08 at 14:16, Jason Merrill wrote:
> On 08 May 2003 12:47:09 -0700, Mark Mitchell <mark@codesourcery.com> wrote:
>
> > I agree that all of this is parenthetical; the key question is whether C
> > needs to have EH constructs or not, not which particular constructs they
> > are.
>
> I think it does. If we want to be able to interleave pthread cleanups from
> C and C++ exception handling, then the C code needs to interface with the
> EH runtime somehow; the obvious way to accomplish this is to use EH for
> cleanups in threaded C code.
>
> For a target that uses sjlj exceptions, this can have exactly the same
> overhead as the old mechanism.
I owe you an answer on this thread; I apologize for the slow reply.
I don't really understand how the SJLJ trick you're describing works,
but I am happy to believe you if you are convinced that it does. I'm
surprised that there's not a setjmp every time you use
pthread_cleanup_push, but it's great if that's not true, and your claim
obviously invalidates my performance complaint.
I'm still concerned in that doing this to C means that there is no going
back -- if something like my alternate-entry-point idea turns out to
make sense for some platform there's no way to implement it because
people will now be using try/finally all through their code.
I'd also still prefer to see a solution that was maximally circumspect;
rather than approach this from a "what is the most elegant language
design?" point of view, I'd prefer a "what is the absolute minimal
feature needed to implement this POSIX requirement?" point of view.
That leads me towards __builtin_pthread_cleanup_push.
For now, I'd much rather we just do as little as possible in the
compiler, and I'd also rather that we encourage people who really want
exceptions to use a language that has them. We do ourselves a
disservice if we implicitly perpetuate the myth that using the C subset
of C++ is somehow worse than just using "straight" C.
In any case, there are some semantics to be defined; if a cleanup throws
an exception, what happens? (You can't call std::terminate in a pure C
program.)
Yours,
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com