comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Accessing finalized values
Date: Mon, 06 May 2013 03:59:36 -0500
Date: 2013-05-06T03:59:36-05:00	[thread overview]
Message-ID: <85r4hk7abr.fsf@stephe-leake.org> (raw)
In-Reply-To: 7a248ba5-9fbc-4326-bbb8-eec3c125d455@googlegroups.com

sbelmont700@gmail.com writes:

> On Friday, May 3, 2013 6:36:08 PM UTC-4, Randy Brukardt wrote:
>> 
>> This is perfectly legitimate, although arguably pathological.
>>
>
> Pathological seems like an understatement; it seems like a pretty
> major catch-22. If the whole purpose of Finalize is "to ensure that
> proper cleanup is performed prior to the object becoming permanently
> inaccessible", but its perfectly legitimate to access the object after
> Finalize has been called, then writing 110% bulletproof code becomes
> much more complex. How is an object supposed to free its resources if
> the resources must still be made available?

The fact that Finalize is called a second time does _not_ mean the
resources must still be available; it means the rest of the program was
unable to keep proper track of whether Finalize had yet been called.

So it is perfectly fine to do something like:

procedure Finalize (Item : my_type)
is begin
   if Item.Finalized then
      ;; nothing more to do
      return;
   else
      ;; free stuff etc
      ...
   end if;
end Finalize;

> For instance, suppose finalization for a File type closes the file; if
> it has to assume that other code might call Read and Write subprograms
> after Finalize has been executed, 

It does _not_ have to assume that; it only has to assume that Finalize
might be called again, not any other operation.


-- 
-- Stephe



  parent reply	other threads:[~2013-05-06  8:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-02 21:00 Accessing finalized values sbelmont700
2013-05-02 22:47 ` Adam Beneschan
2013-05-03 22:36 ` Randy Brukardt
2013-05-05 15:00   ` sbelmont700
2013-05-06  5:45     ` J-P. Rosen
2013-05-06  8:59     ` Stephen Leake [this message]
2013-05-06  9:52     ` Dmitry A. Kazakov
2013-05-06 20:05       ` sbelmont700
2013-05-07  0:51         ` Randy Brukardt
replies disabled

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