comp.lang.ada
 help / color / mirror / Atom feed
* Tail recursion upon task destruction
@ 2009-11-17 10:17 Dmitry A. Kazakov
  2009-11-17 21:38 ` Randy Brukardt
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2009-11-17 10:17 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-11-19  9:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-17 10:17 Tail recursion upon task destruction Dmitry A. Kazakov
2009-11-17 21:38 ` Randy Brukardt
2009-11-18  8:41   ` Dmitry A. Kazakov
2009-11-18 10:31     ` stefan-lucks
2009-11-18 17:48       ` Dmitry A. Kazakov
2009-11-19  9:25       ` Egil Høvik
2009-11-18 11:02     ` Georg Bauhaus
2009-11-18 13:29       ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox