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: a07f3367d7,8536537bd0d9744f,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!news2.euro.net!newsfeed.freenet.de!news.osn.de!diablo1.news.osn.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Tail recursion upon task destruction Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH Date: Tue, 17 Nov 2009 11:17:38 +0100 Message-ID: NNTP-Posting-Date: 17 Nov 2009 11:17:38 CET NNTP-Posting-Host: c6462106.newsspool3.arcor-online.net X-Trace: DXC=ACCo>5FojoU1`E>oC;JXEZMcF=Q^Z^V3X4Fo<]lROoRQ8kF_XAYHKIU>IkT X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8121 Date: 2009-11-17T11:17:38+01:00 List-Id: 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. It seems that there is no way to do this: task Driver_Task (Object : not null access Device) is procedure Free is new Ada.Unchecked_Deallocation (Device, Device_Ptr) Self : Device_Ptr; begin ... accept Shut_Down; Self := Object.all'Unchecked_Access; -- Or whatever way Free (Self); -- This will deadlock end Driver_Task; The core problem is that a task cannot destroy itself, because that would block for task termination, which never to happen. What I do to solve this is an extra "collector task" to await for a rendezvous with Driver_Tasks, accepting a pointer to the Device and then after leaving the rendezvous, freeing it. That looks tedious. Don't we need some kind of "tail recursion" for this destruction pattern? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de