This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: catch(...) and forced unwind
- From: Mark Mitchell <mark at codesourcery dot com>
- To: David Abrahams <dave at boost-consulting dot com>
- Cc: Jason Merrill <jason at redhat dot com>, Nathan Myers <ncm at cantrip dot org>, gcc at gcc dot gnu dot org, Richard Henderson <rth at redhat dot com>, Ulrich Drepper <drepper at redhat dot com>, Benjamin Kosnik <bkoz at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>, wekempf at cox dot net, fjh at cs dot mu dot oz dot au
- Date: Mon, 15 Dec 2003 16:07:55 -0800
- Subject: Re: catch(...) and forced unwind
- Organization: CodeSourcery, LLC
- References: <xypwu91ofvf.fsf@miranda.boston.redhat.com> <ud6at1wvg.fsf@boost-consulting.com> <xypekv9nr9u.fsf@miranda.boston.redhat.com> <u65gkyhv4.fsf@boost-consulting.com> <20031214035909.GE2416@tofu.dreamhost.com> <xypk74xltaa.fsf@miranda.boston.redhat.com> <ullpdlksl.fsf@boost-consulting.com>
- Reply-to: mark at codesourcery dot com
> > That isn't very useful. Just to step back a moment, can we all
> > agree that we want pthread cancellation to run C++ cleanups?
>
> I think so.
Having cancellation result in throwing an exception seems reasonable.
The only other plausible alternative is not unwinding the stack.
That does seem inferior, but I'm not sure it's as bad a choice as people
seem to think. After all, you could always get SIGKILL, which might
leave resources lying around. If pthread_cancel just killed the thread,
the remaining threads have the same problem that remaining process have
after one of their brethren is SIGKILL'd.
> > And that we might have to adjust a few things to make that work?
>
> Yes. The only things I think are crucial here is that functions which
> are specified not to throw (or conditions which are specified not to
> throw) continue to not throw anything, including cancellation, and
> that whatever guarantees functions give about program state in case
> they throw an exception also apply if the exception is a thread
> cancellation. Almost without exception (NPI), code that works in the
> presence of exceptions does not depend on the meaning of said
> exceptions, so giving cancellation exceptions any kind of special
> license to violate assumptions made about other exceptions would be
> wrong.
I agree.
That is essentially what I argued the last time: we should just treat
cancellation like throwing an exception of a special type, and have an
implicit handler for it outside the first function called when the
thread was started. This implicit handler would just terminate the
thread.
If the exception is caught, fine, the thread is not cancelled. If the
exception causes the program to violate a throw spec, fine, the program
calls unexpected().
--
Mark Mitchell <mark@codesourcery.com>
CodeSourcery, LLC