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 X-Google-Thread: 103376,6009c73a58f787a0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-16 10:26:15 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: How to avoid unreferenced objects (mutexes etc) Date: Wed, 16 Jan 2002 13:30:50 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <3c3ee8c8.105408250@News.CIS.DFN.DE> <3c429d1c.2624281@News.CIS.DFN.DE> <3c45865f.2709203@News.CIS.DFN.DE> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:18977 Date: 2002-01-16T13:30:50-05:00 List-Id: "Dmitry A. Kazakov" 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?