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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4bd6ca8f7a1eb225 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.59.229 with SMTP id c5mr3515311pbr.6.1322039152370; Wed, 23 Nov 2011 01:05:52 -0800 (PST) Path: lh20ni8451pbb.0!nntp.google.com!news2.google.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Class with task destructor Date: Wed, 23 Nov 2011 09:05:51 +0000 Organization: A noiseless patient Spider Message-ID: References: <30604696.94.1322013045135.JavaMail.geo-discussion-forums@yqzz20> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="9936"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191mJNyjhE+NsLvgpkVqCaoGVwBsclVEoU=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:yxC1ayYct/rIQsMkYkRws+EPrwo= sha1:5SNWhcav3a30GhOsX4Wtdm0D5r8= Xref: news2.google.com comp.lang.ada:14553 Content-Type: text/plain; charset=us-ascii Date: 2011-11-23T09:05:51+00:00 List-Id: "Dmitry A. Kazakov" writes: > On Tue, 22 Nov 2011 17:50:45 -0800 (PST), Rego, P. wrote: > >> So now I have a class with a task inside and a Constructor, and I >> want to implement a destructor. > [...] > > If you have Start and Finish entries, you don't need terminate > alternative. Use Ada.Finalization.Limited_Controlled as the > base. Make task an access to task component. Initialize should > allocate the task. You don't need Start entry at all. (The only use > for Start is passing additional parameters to the task) From Finalize > you call to Finish and then free the task. The constructing function > *shall* not use pointers. You ought to wait until the task has terminated before freeing it. I can't trace it now, but I think that AdaCore recently fixed a feature where the TCB would be silently not deallocated if the task wasn't terminated. I had to fix this problem by handing off all tasks to be deallocated by a low-priority task, which required some interesting generic/codegen manipulation. I think that that's a *must* not a *shall*, but it's a little while since I did requirementese!