comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Finalization of library level tasks
Date: Sun, 15 Apr 2018 17:15:17 +0200
Date: 2018-04-15T17:15:17+02:00	[thread overview]
Message-ID: <pavqa6$1qdj$1@gioia.aioe.org> (raw)
In-Reply-To: pavp2a$81n$1@dont-email.me

On 2018-04-15 16:54, Jeffrey R. Carter wrote:
> On 04/15/2018 04:12 PM, Dmitry A. Kazakov wrote:
>>
>> The problem is that Finalize is called when the object is declared in 
>> a nested scope:
>>
>>    procedure Main is
>>       Data : X;
>>    begin
>>       Data.Worker := new Worker_Type;
>>    end Main; -- Finalize is called (and terminates the task)
>>
>> This does not work:
>>
>>    package Library_Level is
>>       Data : X;
>>    end Library_Level;
>>
>>    with Library_Level;
>>    procedure Main is
>>    begin
>>       Library_Level.Data.Worker := new Worker_Type;
>>    end Main; -- Finalize is not called (presumably waiting for the task)
> 
> A task declared by an allocator (usually) depends on the thing that the 
> access type is declared in; here, that's a library-level pkg.
> 
> An object declaration such as Data goes out of scope when the thing that 
> it's declared in goes away. In a procedure, the procedure can end and 
> Data can be finalized, even though Data.Worker.all is still running. You 
> might, for example, copy Data.Worker to another variable of the access 
> type that will exist after the procedure call ends. Or you may want the 
> task to exist and run with no way to refer to it; tasks in worker pools 
> often work this way.

That would not work because the task actually has an access discriminant 
pointing the container type.

> When Data is declared in a library-level pkg, it's finalized when the 
> pkg goes out of scope, which doesn't happen until all library-level 
> tasks have terminated. Since Data.Worker has a library-level access 
> type, Data.Worker.all is a library-level task.

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. The effect is that task 
termination is requested prematurely. I hoped that there is some trick, 
e.g. fooling the accessibility rules of the access type, some sort of 
Unchecked_Allocation. Ada 83 had pragma Controlled to require the 
compiler to keep its hands off, alas, it was removed.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


  reply	other threads:[~2018-04-15 15:15 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 [this message]
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
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