Re: [c++-pthreads] The Ada example
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [c++-pthreads] The Ada example



On Thu, 25 Dec 2003 10:34:37 -0500, Ted Baker <baker@xxxxxxxxxx> wrote:

>> More generally, how does Ada deal with this situation?  From looking over
>> 
>>   http://www.adaic.org/standards/95lrm/html/RM-9-8.html
>> 
>> it seems that task abort runs finalizers for objects, but doesn't interact
>> with exception handling.  In C++, the only way to run object destructors is
>> via exception handling, unless we want to define a whole new parallel
>> concept, which I doubt.
>
> You are right. The Ada language defines task abort processing as
> distinct from exception processing.  There is no way in the
> language to handle a task abort.  The finalizers are run, as the
> stack of the task is unwound, and then the task terminates.  What
> can be done inside a finalizer is limited, in an effort to make
> sure the task terminates in a bounded time, but one cannot
> eliminate all possibilities (e.g., a finalizer with an infinite
> loop).

This sounds like the pthread_cleanup_push/pop model in C, or just running
C++ destructors.

> On the other hand, the GNAT (gcc) *implementation* of task abort
> is to treat it as an exception.  This is a "special exception",
> for which the compiler can generate handlers (and does so, to
> implement the execution of finalizers) but the compiler does not
> allow user code to contain such a handler or raise this exception
> other than by task abort.

So similar to a C++ scheme in which catch(...) doesn't catch the
cancellation exception.

> There is another GNAT-specific extension that we found handy.
> That is the "at end" handler.

This sounds like try/finally.

Thanks for the reference point.

Jason