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-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!u-picardie.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Tail recursion upon task destruction Date: Tue, 17 Nov 2009 15:38:45 -0600 Organization: Jacob Sparre Andersen Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1258493930 14407 69.95.181.76 (17 Nov 2009 21:38:50 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 17 Nov 2009 21:38:50 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Xref: g2news1.google.com comp.lang.ada:8133 Date: 2009-11-17T15:38:45-06:00 List-Id: "Dmitry A. Kazakov" wrote in message news:jv8fpjlb56be$.1afg8uuwigjop$.dlg@40tude.net... > Consider a task encapsulated in an object in either way: > > type Device is > Driver : Driver_Task (Device'Access); > > or > > type Device is > Driver : not null access Driver_Task := Driver_Task (Device'Access); > > Let the object is allocated dynamically and we wanted to destroy it from > the task. Ada does not allow an object to destroy/free itself. That's generally a good thing, because such an object cannot be an ADT (it cannot be used as the element of a container, for instance), and such a model would require a far more complex scheme of frame completion than is used now: wait for all taks, then finalize all objects, then free all memory. I realize that there are a few cases where some other scheme would be better (we struggled with this in CLAW, as the finalization of library level objects tried to use the GUI task which of course has already terminated), but they would require such an earthquake in semantics as not to make any sense for Ada. In your particular case, I don't understand why you don't use nesting to solve the problem. That is, put the objectinside of the task (either directly or logically), so it can be destroyed when the task needs to do that. That would look something like: task type Device; task type Device is Device_Data : not null access Device_Data_Type := new Device_Data_Type; begin ... Free (Device_Data); end Device; Note: you'd need a named access type to actually do this - I used an anonymous one simply to make my point clearer. Randy.