This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



You'd have to have sigpause (and the other cancellable calls)
conditionalised on __cplusplus, and then to permit users to write
programs in a mix of C and C++ you'd have to define some way to
convert the exceptions thrown in C++ to the sj/lj calls in C.
OK, I think I see the problem.

Suppose the dynamic stack of your code looks like:

 C++ -> C -> C++ -> sigpause

When cancellation occurs, you want to have sigpause throw an exception,
run cleanups in C++, then run the pthread_cleanup_push stuff in C,
the outer C++ cleanups agagin, etc.

If the -> transitions are shared library boundaries, you have no problem;
you can have your personality routines do the right thing.  In fact, you
can do that anyhow, if you mark your .o's as being C or C++.

In C, you have pthread_cleanup_push keep a stack of cleanups.
When unwinding through a a C .o, you run the stack.  In C++, you use
my pthread_cleanup_push class so that it just happens by itself.

You have sigpause throw an exception, and you have a handler at the top
of the stack, to finish the thread exit.  (This last bit is what was
going to happen with try/finally anyhow, I assume.)

--
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]