From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Finalization of library level tasks Date: Sun, 15 Apr 2018 16:54:01 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 15 Apr 2018 14:54:02 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="49ba640083832927bb2c73dfc6f6db66"; logging-data="8247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vUPd6unNFbIYo4AV/ZoukYBnnGM/Pu1k=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:JVKA0bRg0UI2K+he9W7oWmZCJTc= Xref: reader02.eternal-september.org comp.lang.ada:51518 Date: 2018-04-15T16:54:01+02:00 List-Id: 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. 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. -- Jeff Carter "Well, a gala day is enough for me. I don't think I can handle any more." Duck Soup 93