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-17 00:58:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) Newsgroups: comp.lang.ada Subject: Re: How to avoid unreferenced objects (mutexes etc) Date: Thu, 17 Jan 2002 08:58:07 GMT Message-ID: <3c468b1a.69461281@News.CIS.DFN.DE> References: <3c3ee8c8.105408250@News.CIS.DFN.DE> <3c429d1c.2624281@News.CIS.DFN.DE> <3c45865f.2709203@News.CIS.DFN.DE> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) X-Trace: fu-berlin.de 1011257887 32088285 212.79.194.111 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:18999 Date: 2002-01-17T08:58:07+00:00 List-Id: On Wed, 16 Jan 2002 13:30:50 -0500, "Matthew Heaney" wrote: >"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. Yes it works (I have actually used that) for some cases. It does not work when the type is non-abstract and tagged. Sorry for my misleading comment. I believe it is worth to allow that for all types, i.e. to allow overriding a non-abstract subroutine with an abstract one. A dispatching call to a disallowed subprogram will then raise an exception [like when tags of arguments are different]. >> >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? Surely. But I prefer my solution because it hides nasty pointers in the implementation. Your variant exposes them to the user. Using C++ for a long time one becomes pointer-allergic. (:-)) In fact it is the *same* solution, i.e. pointers are inevitable. Would not it be better to add to Ada.Finalization procedure Postinitialize (..); -- All tasks are already running procedure Prefinalize (..); -- All tasks are still running ? Regards, Dmitry Kazakov