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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3cfaa627fc3366de X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Task origin track from a class Date: Tue, 12 Jul 2011 09:41:24 +0200 Organization: cbb software GmbH Message-ID: <4o0rnqqqec1s$.19h46xsbjbku2.dlg@40tude.net> References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news2.google.com comp.lang.ada:21147 Date: 2011-07-12T09:41:24+02:00 List-Id: On Mon, 11 Jul 2011 20:24:04 -0700 (PDT), Rego, P. wrote: > I have a class Def_Class which defines a record which is a task. You shouldn't do that, because most likely you will later have serious (unsolvable) problems with the object's finalization. Unless the task has somewhere a select with an open terminate alternative, the object's finalization will hang. Note that deriving it from Ada.Finalization.Limited_Controlled won't help. Consider this: type Parent; task type Worker (Data : not null access Parent'Class) is entry Do_Stuff; entry Stop; end Worker; type Parent is new Ada.Finalization.Limited_Controlled with record My_Task : Worker (Parent'Access); end record; overriding procedure Finalize (Object : in out Parent); and the implementation: procedure Finalize (Object : in out Parent) is begin Object.My_Task.Stop; -- Kill the task end Finalize; task body Worker is begin loop select accept Do_Stuff; -- Some useful stuff to do or accept Stop; exit; end select; end loop; end Worker; This does *not* work! The problem is that the task must complete *before* Finalize of the containing object is called. It would work if the select of the task would have: or terminate; -- Complete if asked (and then the Stop entry call removed from Finalize, of course). The problem with this is that too frequently there is no way to add the terminate alternative (for various reasons, which are irrelevant here). So the unfortunate rule of the thumb is: never use task components, but access to task instead. From Finalize you would call Stop entry or an equivalent and then free the task object using Unchecked_Deallocation. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de