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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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.15.105 with SMTP id w9mr9985598pbc.7.1322189903529; Thu, 24 Nov 2011 18:58:23 -0800 (PST) Path: lh20ni14952pbb.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: "Rego, P." Newsgroups: comp.lang.ada Subject: Re: Class with task destructor Date: Thu, 24 Nov 2011 18:44:35 -0800 (PST) Organization: http://groups.google.com Message-ID: <7401998.82.1322189075090.JavaMail.geo-discussion-forums@yqny18> References: <30604696.94.1322013045135.JavaMail.geo-discussion-forums@yqzz20> Reply-To: comp.lang.ada@googlegroups.com NNTP-Posting-Host: 189.110.14.179 Mime-Version: 1.0 X-Trace: posting.google.com 1322189903 29545 127.0.0.1 (25 Nov 2011 02:58:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 25 Nov 2011 02:58:23 +0000 (UTC) Cc: mailbox@dmitry-kazakov.de In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=189.110.14.179; posting-account=TRgI1QoAAABSsYi-ox3Pi6N-JEKKU0cu User-Agent: G2/1.0 X-Google-Web-Client: true Xref: news2.google.com comp.lang.ada:14621 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-11-24T18:44:35-08:00 List-Id: > 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. 1) Why should I need to use Finalize (instead of direct T.Primary.Finish in Destruct)? Wouldn't be simpler if I used procedure Destruct (T : access Test_Class) is T_Ptr : Test_Class_Ptr := Test_Class_Ptr (T); begin T.Primary.Finish; Free (T_Ptr); end Destruct; instead of overriding procedure Finalize is begin T.Primary.Finish; end if; procedure Destruct (T : access Test_Class) is T_Ptr : Test_Class_Ptr := Test_Class_Ptr (T); begin T.Finalize; Free (T_Ptr); end Destruct; ? 2) Anyway, you're suggesting task type Primary_Task (This : not null access Test_Class) is entry Pause; entry Release; entry Finish; end Primary_Task; type Test_Class is new Limited_Controlled with record Some_Info : Integer; Primary : Primary_Task (Test_Class'Access); end record; (...) task body Primary_Task is begin Main_Loop : loop select accept Pause; select accept Release; or accept Finish; exit Main_Loop; end select; or accept Finish; exit Main_Loop; else Put ("^"&Integer'Image (This.Some_Info)); delay 0.5; end select; end loop Main_Loop; end Primary_Task; (...) function Construct return Test_Class_Ptr is T_Ptr : constant Test_Class_Ptr := new Test_Class; begin T_Ptr.Some_Info := 1; T_Ptr.Initialize; return T_Ptr; end Construct; Right? 3) I didn't override the Initialize. And I have taken out the Start entry, but this leads to ^ 5242971^ 1^ 1^ 1^ 1^ 1^ 1^ 1^ 1^ 1 because in the first cycle the Some_Info was not initialized. Maybe I misunderstand when you said to take out Start entry? > The constructing function *shall* not use pointers. I will use them in a list, that's why I used a pointer.