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!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Finalization of library level tasks Date: Fri, 27 Apr 2018 10:57:32 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: MyFhHs417jM9AgzRpXn7yg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 X-Notice: Filtered by postfilter v. 0.8.3 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:51745 Date: 2018-04-27T10:57:32+02:00 List-Id: On 27/04/2018 10:32, AdaMagica wrote: > Am Freitag, 27. April 2018 09:37:46 UTC+2 schrieb Dmitry A. Kazakov: >> You *can* finalize the class of the object containing the task with the >> task component still running: >> >> type Container_Type is .. tagged ... >> T : Task_Type; >> >> The order of finalization must be: >> >> Finalize Container_Type'Class; >> Stop T; -- Existing order > > IIUC, you mean the task T is stopped anywhere in the middle of its work? No, I mean that the task is awaited, e.g. to accept terminate. What I meant is that finalization of a class object does not need to wait for the task to end. Therefore from the class' Finalize you could ask the task to stop: task type Task_Type is entry Shutdown; end Task_Type; type Container_Type is new Ada.Finalization.Limited_Controlled with record T : Task_Type; end record; procedure Finalize (Object : in out Container_Type'Class); for Container_Type'Class'Finalize use Finalize ; -- Whatever syntax procedure Finalize (Object : in out Container_Type'Class) is begin Object.T.Shutdown; -- You cannot do that from normal Finalize, end Finalize; -- it is too late then Presently class finalization is null. BTW, after class finalization dispatching calls on the class must result in an exception. It should have been a bounded error to dispatch from Initialize or Finalize. One of the inconsistencies of controlled types design is that dispatching is allowed in Finalization <=> the class considered operational, but task components are not running <=> the class considered non-operational. Either one or another. > Ada calls this abort. This means a lot of things may be left in an invalid state. Yes. Task abort is almost never usable. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de