From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: Reference counting and idempotent finalize
Date: Wed, 11 Sep 2013 05:21:46 -0700
Date: 2013-09-11T05:21:46-07:00 [thread overview]
Message-ID: <l0pn8q$rih$1@adenine.netfront.net> (raw)
In-Reply-To: <slrnl30ie3.1lme.lithiumcat@sigil.instinctive.eu>
On 09/11/2013 03:45 AM, Natasha Kerensikova wrote:
> Access_Value.all.Counter := Access_Value.all.Counter - 1;
What happens if Counter is already zero? Can Counter become negative, and if so, what does it mean for Counter to be
negative?
> I neglected the possibility of exceptional flow interruption because I
> felt that an exception in Finalize triggers the end of the world (the
> same way I've felt for a long time the idempotency requirement). Now
> having done the research, 7.6.1(13) doesn't really mention the world
> ending, that looks quite close to it, doesn't it?
ARM 7.6.1 says, "It is a bounded error for a call on Finalize or Adjust that occurs as part of object finalization or
assignment to propagate an exception." My practice has, therefore, been to always ensure that Finalize cannot propagate
an exception.
FWIW, Finalize from PragmARC.Safe_Pointers looks like
procedure Finalize (Item : in out Safe_Pointer) is
procedure Free is new Ada.Unchecked_Deallocation (Object => Safe_Group, Name => Name);
begin -- Finalize
if Item.Ptr /= null then
if Item.Ptr.Count > 0 then
Item.Ptr.Count := Item.Ptr.Count - 1;
end if;
if Item.Ptr.Count = 0 then
Free (Item.Ptr);
end if;
Item.Ptr := null;
end if;
end Finalize;
I have convinced myself that this cannot propagate an exception (except Storage_Error, of course, since anything can
result in Storage_Error). It might be easier (and safer) to always have "exception when others => null;" on every Finalize.
The PragmAda Reusable Components, including the full implementation of PragmARC.Safe_Pointers, are at
pragmada.x10hosting.com
--
Jeff Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
next prev parent reply other threads:[~2013-09-11 12:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-11 10:45 Reference counting and idempotent finalize Natasha Kerensikova
2013-09-11 11:21 ` AdaMagica
2013-09-11 12:12 ` Dmitry A. Kazakov
2013-09-12 5:34 ` Natasha Kerensikova
2013-09-12 7:33 ` Dmitry A. Kazakov
2013-09-11 12:16 ` Dmitry A. Kazakov
2013-09-12 4:53 ` Natasha Kerensikova
2013-09-11 12:21 ` Jeffrey R. Carter [this message]
2013-09-11 20:03 ` Simon Wright
2013-09-12 4:46 ` Natasha Kerensikova
2013-09-12 5:05 ` Natasha Kerensikova
2013-09-12 7:54 ` Dmitry A. Kazakov
2013-09-12 17:03 ` Jeffrey R. Carter
2013-09-11 13:50 ` Pascal Obry
2013-09-12 4:56 ` Natasha Kerensikova
2013-09-12 14:33 ` Simon Wright
2013-09-12 15:40 ` Pascal Obry
2013-09-12 10:23 ` sbelmont700
2013-09-30 6:25 ` Natasha Kerensikova
2013-09-30 10:02 ` AdaMagica
2013-10-01 6:22 ` Natasha Kerensikova
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox