comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Finalization of library level tasks
Date: Thu, 26 Apr 2018 17:25:50 -0500
Date: 2018-04-26T17:25:50-05:00	[thread overview]
Message-ID: <pbtjlf$k6q$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: pbs4km$doq$1@gioia.aioe.org

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:pbs4km$doq$1@gioia.aioe.org...
> On 26/04/2018 01:46, Randy Brukardt wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:pavqa6$1qdj$1@gioia.aioe.org...
>> ...
>>> Yes. The problem is the order of finalization. For some unclear reason 
>>> the
>>> task's access type is attempted before the object that contains that
>>> access type because they are in the same scope.
>>
>> It's not unclear - tasks have to terminate before objects are finalized 
>> so
>> that the tasks aren't trying to use finalized objects. If the object is a
>> protected object, that could be a really bad deal (remember that 
>> finalizing
>> a protected object raises tasking error in any queued task and prevents
>> future calls).
>
> It is all objects, not just ones containing the task. You could have:
>
>    package A is
>       task type Foo ...
>       X : Foo;
>    end A;
>
>    package A.B is
>       type Bar is new Ada.Finalization.Controlled ...
>       Y : Bar;
>    end A.B;
>
> Even so, finalization of Y will await termination of X!

It has to. There is no way for the compiler to know that there is no way for 
X to access Y.

> The deadlock in the RM is constructed to prevent any possible way to break 
> it.

Correct, and that is by design. An unbreakable premise of Ada is that 
finalization of objects will always be done no matter what happens. That's 
why subpools have a finalization mechanism, Unchecked_Deallocation does 
finalization, assignment does finalization, ad nauseum. The designer of an 
Ada library (ADT) can always be assured that their last wishes will be 
executed regardless of what horrors the client tries to invent. This is a 
critical property for reusability.

> There are dozens ways to fix the mess but there seems no interest at all.

Correction: there are dozens of ways to make a worse mess. There is no way 
to "fix" the issue, because any change to the rules just breaks in some 
other case. Or completely destroys the ability of ADTs to assume that 
finalization happens.

When we ran into the problem in the Claw design, I spent a lot of time 
trying to come up with a fix. I couldn't find anything that didn't have 
worse problems in some cases. I believe other ARG members did the same 
thing; the environment task solution seemed to be the best workaround (it 
works great in Claw, presuming of course that the compiler implements it 
correctly).

Claw, for instance, uses a number of locks. We had problems with compilers 
finalizing those locks before awaiting tasks, meaning that the tasks got 
Program_Error for no expected reason. (And one compiler that will remain 
nameless just crashed if you called such a lock; there's an ACATS test for 
that, too, these days.)

The critical thing from an Ada perspective is that the rules are 
well-defined and don't change from implementation-to-implementation. Then it 
is always possible to find a solution (not necessarily an easy one).

Task termination is rarely considered in Ada books, yet it is one of the 
hardest things to accomplish. I don't have any termination technique at all 
in the spam filter, because I couldn't think of anything that would actually 
work. Luckily, you can just kill the process from Windows in the few cases 
where you need to shut the thing down.

One of the advantages of the parallelism model in Ada 2020 is that you don't 
have to write explicit tasks so you don't have to deal with termination of 
them.

                          Randy.



  reply	other threads:[~2018-04-26 22:25 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-15 13:40 Finalization of library level tasks Dmitry A. Kazakov
2018-04-15 14:02 ` Jeffrey R. Carter
2018-04-15 14:12   ` Dmitry A. Kazakov
2018-04-15 14:54     ` Jeffrey R. Carter
2018-04-15 15:15       ` Dmitry A. Kazakov
2018-04-15 15:46         ` AdaMagica
2018-04-15 15:53           ` Dmitry A. Kazakov
2018-04-15 17:17           ` AdaMagica
2018-04-15 17:40             ` Dmitry A. Kazakov
2018-04-15 19:32               ` Egil H H
2018-04-15 20:09                 ` Dmitry A. Kazakov
2018-04-25 23:49                   ` Randy Brukardt
2018-04-16  5:19               ` J-P. Rosen
2018-04-16  7:30                 ` Dmitry A. Kazakov
2018-04-16  7:55                   ` J-P. Rosen
2018-04-16  8:13                     ` Dmitry A. Kazakov
2018-04-16  8:32                       ` J-P. Rosen
2018-04-16 15:26                         ` Dmitry A. Kazakov
2018-04-17  9:51                           ` AdaMagica
2018-04-17 12:31                             ` Dmitry A. Kazakov
2018-04-17 15:37                               ` Jeffrey R. Carter
2018-04-17 15:57                                 ` Dmitry A. Kazakov
2018-04-17 20:16                                   ` Jeffrey R. Carter
2018-04-17 20:59                                     ` Dmitry A. Kazakov
2018-04-18  5:20                                       ` J-P. Rosen
2018-04-17 20:55                                   ` J-P. Rosen
2018-04-17 21:23                                     ` Dmitry A. Kazakov
2018-04-18  5:26                                       ` J-P. Rosen
2018-04-26  0:02                                         ` Randy Brukardt
2018-04-18  8:06                               ` AdaMagica
2018-04-18  8:25                                 ` Dmitry A. Kazakov
2018-04-18  8:52                                   ` Egil H H
2018-04-18  9:58                                     ` Dmitry A. Kazakov
2018-04-18 11:33                                       ` J-P. Rosen
2018-04-18 11:58                                         ` Dmitry A. Kazakov
2018-04-18 12:00                                           ` J-P. Rosen
2018-04-18 12:25                                             ` Dmitry A. Kazakov
2018-04-18 13:51                                               ` J-P. Rosen
2018-04-18 14:12                                                 ` Dmitry A. Kazakov
2018-04-18 14:52                                                   ` J-P. Rosen
2018-04-18 15:04                                                     ` Dmitry A. Kazakov
2018-04-18 20:26                                                       ` AdaMagica
2018-04-18 21:00                                                         ` Dmitry A. Kazakov
2018-04-18 20:40                                                     ` AdaMagica
2018-04-19  7:34                                                       ` Simon Wright
2018-04-18 21:29                                                     ` J-P. Rosen
2018-04-19  7:32                                                       ` Dmitry A. Kazakov
2018-04-26  0:04                                       ` Randy Brukardt
2018-04-26  8:56                                         ` Dmitry A. Kazakov
2018-04-26 22:10                                           ` Randy Brukardt
2018-04-27  4:48                                             ` J-P. Rosen
2018-04-27 20:52                                               ` Randy Brukardt
2018-04-17 11:16                           ` J-P. Rosen
2018-04-17 12:47                             ` Dmitry A. Kazakov
2018-04-17 14:08                               ` J-P. Rosen
2018-04-17 14:47                                 ` Dmitry A. Kazakov
2018-04-17 22:00                                   ` Robert A Duff
2018-04-18  7:25                                     ` Dmitry A. Kazakov
2018-04-25 23:54                           ` Randy Brukardt
2018-04-26 16:22                             ` Jeffrey R. Carter
2018-04-26 16:43                               ` Dmitry A. Kazakov
2018-04-26 20:19                                 ` J-P. Rosen
2018-04-16  9:19               ` AdaMagica
2018-04-16 15:15                 ` Dmitry A. Kazakov
2018-04-19 20:39           ` G. B.
2018-04-20  7:27             ` Dmitry A. Kazakov
2018-04-25 23:46         ` Randy Brukardt
2018-04-26  9:03           ` Dmitry A. Kazakov
2018-04-26 22:25             ` Randy Brukardt [this message]
2018-04-27  7:37               ` Dmitry A. Kazakov
2018-04-27  8:32                 ` AdaMagica
2018-04-27  8:57                   ` Dmitry A. Kazakov
2018-04-27 21:08                 ` Randy Brukardt
2018-04-28  8:35                   ` Dmitry A. Kazakov
2018-04-29 17:41                     ` AdaMagica
2018-04-29 19:36                       ` Dmitry A. Kazakov
2018-04-30 12:27                         ` AdaMagica
2018-04-30 13:03                           ` Dmitry A. Kazakov
2018-04-30 16:52                           ` Jeffrey R. Carter
2018-04-30 17:06                             ` Dmitry A. Kazakov
2018-05-01  9:17                             ` AdaMagica
2018-05-01  9:40                               ` Dmitry A. Kazakov
2018-05-01 11:18                               ` Jeffrey R. Carter
2018-05-01 11:27                                 ` Dmitry A. Kazakov
2018-05-01 15:54                                 ` Niklas Holsti
2018-05-02 14:34                                   ` AdaMagica
2018-05-02 14:50                                     ` Dmitry A. Kazakov
2018-05-01  2:27                     ` Randy Brukardt
2018-05-01  6:59                       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox