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=0.1 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a7dd909b9ed9f6d5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-26 07:00:04 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.direct.ca!look.ca!feed.news.qwest.net!dfw-peer.news.verio.net!iad-feed.news.verio.net!news.verio.net!carrier.kiev.ua!news.kiev.sovam.com!Svitonline.COM!not-for-mail From: "Maxim Reznik" Newsgroups: comp.lang.ada Subject: Re: GNAT: Unbounded_Strings Date: Tue, 26 Jun 2001 16:58:28 +0300 Organization: Svit Online (post does not reflect views of Golden Telecom) Message-ID: <9ha4gu$k32$1@news.kiev.sovam.com> References: <9h9a9n$6bm$1@news.kiev.sovam.com> <87r8w7h8v4.fsf@deneb.enyo.de> <873d8nfn0j.fsf@deneb.enyo.de> NNTP-Posting-Host: 212.109.37.91 X-Trace: news.kiev.sovam.com 993564002 20578 212.109.37.91 (26 Jun 2001 14:00:02 GMT) X-Complaints-To: abuse@svitonline.com NNTP-Posting-Date: 26 Jun 2001 14:00:02 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2462.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000 Xref: archiver1.google.com comp.lang.ada:9115 Date: 2001-06-26T14:00:02+00:00 List-Id: "Florian Weimer" wrote in message news:873d8nfn0j.fsf@deneb.enyo.de... > Florian Weimer writes: > > > "Maxim Reznik" writes: > > > >> I propose another implementation of Unbounded_Strings using > >> reference counting. > > > > Your implementation is not task safe, > > I was asked to explain this, so here we go. [...] > However, your code does not synchronize the two task when the a local > copy of a shared string is made. As a result, your subprograms are > not reentrant, and therefore not conforming to the implementation > requirement quoted above. Thank you for your explanation. Modifying of a shared string is synchronized by reference counter. While this counter >1 any change of shared string can't be done. One thing I could lose sight of is synchronization of counter itself. Are following changes enough ? ++++ protected type Counter is procedure Increment; procedure Decrement; function Value return Natural; private Count : Natural := 0; end Counter; type Shared_String (Length : Natural) is record Space : String (1 .. Length); Count : Counter; end record; -- replace all references to Share.Count with protected procedures. ++++ I think operators ++++ if Source.Share.Count.Value = 1 then Change_Somehow( Source.Share.Space ); else Make_A_Copy Decrement_Count (Source.Share); end if; ++++ are Ok, because of Count.Value=1 means that there isn't any other references to string and nobody can change neither Share.Count nor Share.Space. One bad consequence of this solution is 40 bytes overhead for each strings. -- Maxim Reznik