comp.lang.ada
 help / color / mirror / Atom feed
From: "Maxim Reznik" <max1@mbank.com.ua>
Subject: Re: GNAT: Unbounded_Strings
Date: Tue, 26 Jun 2001 16:58:28 +0300
Date: 2001-06-26T14:00:02+00:00	[thread overview]
Message-ID: <9ha4gu$k32$1@news.kiev.sovam.com> (raw)
In-Reply-To: 873d8nfn0j.fsf@deneb.enyo.de


"Florian Weimer" <fw@deneb.enyo.de> wrote in message news:873d8nfn0j.fsf@deneb.enyo.de...
> Florian Weimer <fw@deneb.enyo.de> writes:
>
> > "Maxim Reznik" <max1@mbank.com.ua> 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






  reply	other threads:[~2001-06-26 13:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9h9a9n$6bm$1@news.kiev.sovam.com>
2001-06-26  9:45 ` GNAT: Unbounded_Strings Florian Weimer
2001-06-26  9:46 ` Florian Weimer
2001-06-26 12:23   ` Florian Weimer
2001-06-26 13:58     ` Maxim Reznik [this message]
2001-06-26 15:28       ` Florian Weimer
replies disabled

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