Re: [c++-pthreads] Re: thread-safety definition
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [c++-pthreads] Re: thread-safety definition



> A catch(...) without a re-throw isn't necessarily a silly thing to do, 
> especially in a destructor.  Sometimes, the only alternative is to risk 
> a call to terminate().

For this reason, Ada requires that abort (what we are calling
cancellation here) be deferred automatically during the execution
of finalizers (what we are calling destructors here).

It is important that, as you say, finalizers can catch exceptions
and encapsulate them, allowing finalization to continue with the
next finalizer.

This is an important point, that one may have recursive/nested
exceptions, i.e., while handling one exception another exception
may be raised and handled, upon completion of which processing of
the the first exception resumes.

In particular, if one is executing a chain of
finalizers/descructors due to exception propagation causing one to
exit the scope of an object with finalization, the
finalizer/destructor should be able to catch local exceptions that
might be raised/thrown by its own code, without re-raising them.
On return from the finalizer/destructor the propagation of the
other exception then continues, unaffected.

This is what you also want with abort/cancellation.  In the
processing of the cancellation you execute cleanup handlers,
finalizers, desctructors (or whatever you choose to call them)
as you unwind the stack.  Each of those may generate new
exceptions, and handle them locally.  That does not stop the
unwinding of the stack until the original abort/cancellation
is caught and handled (if you allow that to be caught and
handled) or the thread terminates.

--Ted