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: [3.3] Followup to C++ forced unwinding


On Wed, 2003-04-30 at 17:17, Richard Henderson wrote:
> On Wed, Apr 30, 2003 at 04:50:53PM -0700, Nathan Myers wrote:
> > Any thread can prevent cancellation by putting "while (true);" in
> > a destructor.  Once control leaves the catch block, the thread can't 
> > do any more externally visible work anyway, because that would touch 
> > another cancellation point, which (I assume) would throw again.  
> 
> Yeah, but you have to work at it to not cancel the thread
> (via exit or longjmp or infinite loop) from a destructor,
> whereas it's easy to forget to rethrow inside a catch(...).
> 
> Thus, IMO destructors should be preferred over catch(...)
> for *all* cleanup operations, not just for this cancellation
> question.

I agree.  Users should be encouraged to use destructors;
resource-acquisition-as-initialization is a good C++ idiom.

But we shouldn't go silently breaking millions of lines of until-now
exception-safe ISO-conformant code that happens to use "catch(...)"
rather than destructors.  I'd ever so much rather debug a
why-didn't-my-thread-go-away bug than a
why-is-my-data-in-an-inconsistent-state bug.

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


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