__attribute__((cleanup(function)) versus try/finally

Mark Mitchell mark@codesourcery.com
Thu May 8 19:47:00 GMT 2003


> Err...  You're not using try/finally above,

That was my point: try/finally isn't really the ideal construct.

Your version does work, of course -- as does my try/catch expression of
the idea, modulo your comments below.

> and you're not necessarily
> using the values of f and a that were passed to pthread_cleanup_push.

This was a mistake, thanks.  You're right that the values need to be
saved, of course.

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.

Let's just drop that train of thought; it's not going to be productive. 
I was just musing.

It would be nice, though, if the "goto" issue got back to the right
people; that should definitely be specified.  In the same light, the
behavior of "break" and "continue" should be specified; those are also
ways of exiting the scope.  

Undefined behavior might be the right answer.  Running the cleanup might
not be a good idea; the argument to pthread_cleanup_pop means that the
designers thought that sometimes you don't want to run the cleanup. 
(It's not really like a C++ destructor.)  

Maybe jumping out of the scope should just be ill-formed, no diagnostic
required.

I'm not sure, but this isn't the right forum to decide anyhow; I'd just
like for the POSIX people to know about the issue.

-- 
Mark Mitchell <mark@codesourcery.com>
CodeSourcery, LLC



More information about the Gcc mailing list