From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: How to avoid unreferenced objects (mutexes etc)
Date: Wed, 16 Jan 2002 13:30:50 -0500
Date: 2002-01-16T13:30:50-05:00 [thread overview]
Message-ID: <u4bhe4qre43f89@corp.supernews.com> (raw)
In-Reply-To: 3c45865f.2709203@News.CIS.DFN.DE
"Dmitry A. Kazakov" <dmitry@elros.cbb-automation.de> wrote in message
news:3c45865f.2709203@News.CIS.DFN.DE...
> However, I always wished Ada having an ability to disallow primitive
> operations. Like:
>
> type Unordered is new Integer;
> function ">" (Left, Right : Unordered) is abstract; -- Disallow ">"
I'm confused by your comment. Ada95 *can* do this.
I do this to turn off predefined equality for a composite type whose
component type is a generic formal non-limited type, so that I don't
accidently use predefined array comparisons using the predefined equality
for the formal type, which reemerges in the composite type, ie
generic
type T is private;
package GP is
type T_Array is array (Positive range <>) of T;
function "=" (L, R : T_Array) return Boolean is abstract;
end GP;
Note that passing in an equality operator doesn't work here, because
predefined equality reemerges *again* in the array declaration. So I just
turn off array comparison, in order to prevent any accidents.
> >But the tagged type could contain a component of a task type.
>
> Yes, and another problem as well. Finalize is called *after* all task
> components has been terminated. So when the object is being destroyed
> you cannot notify tasks about that. You must use pointers to tasks if
> you need a "prepare-to-die" notification.
But you can use a two-part termination:
package P is
type T (<>) is abstract tagged limited private;
type T_Class_Access is access all T'Class;
procedure Op (O : access T) is abstract;
procedure Free (O : in out T_Class_Access);
private
type T_Task_Type (O : access T'Class) is
entry E;
end T_Task_Type;
type T is abstract new Limited_Controlled with record
T_Task : T_Task_Type (T'Access);
end record;
procedure Do_Free (O : access T); --private, primitive op
end P;
package body P is
procedure Do_Free (O : access T) is
begin
null;
end;
procedure Free (O : in out T_Class_Access) is
procedure Deallocate is new Ada.UD (T'Class, T_Class_Access);
begin
if O /= null then
Do_Free (O);
Deallocate (O);
end if;
end Free;
...
end P;
Each type in T'Class provides a factory function to construct instances. To
destruct an instance, the client calls P.Free. Free is implemented by
calling dispatching Do_Free, which notifies the object that it's about to be
destroyed. It then calls deallocate, which triggers the Finalize call.
Won't this work?
next prev parent reply other threads:[~2002-01-16 18:30 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-11 13:48 How to avoid unreferenced objects (mutexes etc) Dmitry A. Kazakov
2002-01-11 13:52 ` Lutz Donnerhacke
2002-01-11 14:47 ` Robert A Duff
2002-01-11 18:02 ` Jeffrey Carter
2002-01-11 19:40 ` Robert Dewar
2002-01-12 10:18 ` Martin Dowie
2002-01-14 8:54 ` Dmitry A. Kazakov
2002-01-12 1:11 ` Nick Roberts
2002-01-12 22:04 ` Matthew Heaney
2002-01-13 5:45 ` Nick Roberts
2002-01-13 8:21 ` tmoran
2002-01-13 16:12 ` Nick Roberts
2002-01-13 15:08 ` Simon Wright
2002-01-15 17:53 ` Nick Roberts
2002-01-13 16:51 ` Jeffrey Carter
2002-01-14 23:32 ` Matthew Heaney
2002-01-15 8:53 ` Dmitry A. Kazakov
2002-01-14 8:31 ` Jean-Pierre Rosen
2002-01-14 9:42 ` Dmitry A. Kazakov
2002-01-15 15:41 ` Matthew Heaney
2002-01-15 16:18 ` Hyman Rosen
2002-01-15 16:57 ` Darren New
2002-01-15 18:57 ` Matthew Heaney
2002-01-16 0:57 ` Darren New
2002-01-16 16:35 ` Stephen Leake
2002-01-16 18:07 ` Darren New
2002-01-16 23:18 ` Matthew Heaney
2002-01-16 23:04 ` Matthew Heaney
2002-01-17 0:21 ` Darren New
2002-01-16 15:18 ` Dmitry A. Kazakov
2002-01-15 18:59 ` Nick Roberts
2002-01-16 15:05 ` Dmitry A. Kazakov
2002-01-16 18:30 ` Matthew Heaney [this message]
2002-01-17 8:58 ` Dmitry A. Kazakov
2002-01-17 9:19 ` Lutz Donnerhacke
2002-01-17 10:42 ` Dmitry A. Kazakov
2002-01-17 10:55 ` Lutz Donnerhacke
2002-01-17 15:30 ` Dmitry A. Kazakov
2002-01-17 16:29 ` Lutz Donnerhacke
2002-01-16 20:28 ` Robert A Duff
2002-01-17 19:05 ` Nick Roberts
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox