comp.lang.ada
 help / color / mirror / Atom feed
From: ytomino <aghia05@gmail.com>
Subject: Problem in "X (1).Re := X (1).Re + 1"
Date: Sat, 5 May 2012 05:55:39 -0700 (PDT)
Date: 2012-05-05T05:55:39-07:00	[thread overview]
Message-ID: <13177506.38.1336222539273.JavaMail.geo-discussion-forums@pbtg6> (raw)

This is a thought experiment.

First, in RM 4.1.6:

* when the generalized_indexing is used within a primary where a name denoting a constant is permitted.

This means

declare
   package V is new Vectors (Complex);
   X : V.Vector;
begin
   X (1).Re := X (1).Re + 1;
end;

is interpreted as

declare
   package V is new Vectors (Complex);
   X : V.Vector;
begin
   Reference (X, 1).Element.all.Re := Constant_Reference (X, 1).Element.all.Re + 1;
end;

Is this OK?

If this is the truth, and if Vectors is implemented by reference-counting.
(I don't know copy-on-write is permitted in Ada.Containers.Vectors. Otherwise, please assume my original container like Vectors.)

Well then...
May a next eval-order problem be caused or not?

1. eval "Constant_Reference (X, 1)" => get an accessor pointing to shared data. (reference counter > 1)
2. eval "Reference (X, 1)" => do copy-on-write, and get an accessor pointing to new unshared data.
3. eval ".Element.all.Re" in right side => access *old* shared data. <- !!!!
4. eval ".Element.all.Re" in left side => access new data.
5. eval + 1 => calculate old data + 1.
6. eval assignment => store the result into new data.

(Real compiler usually does not generate the strange order such as this. But "arbitrary order" is spelled out in RM 5.2.)

Of course, the result is same if shared data is alive.
However, on the worst case, the other task can deallocate shared data during from 1 to 3. Or, if the element type is controlled type or havs access value.

What do you think?

Thanks.



             reply	other threads:[~2012-05-05 12:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-05 12:55 ytomino [this message]
2012-05-07 15:37 ` Problem in "X (1).Re := X (1).Re + 1" Adam Beneschan
2012-05-07 18:53   ` ytomino
2012-05-07 21:28     ` Adam Beneschan
2012-05-08  1:14       ` Randy Brukardt
2012-05-08 17:14         ` Adam Beneschan
2012-05-08 22:29           ` Randy Brukardt
2012-05-09  8:41             ` ytomino
2012-05-10  0:52               ` Randy Brukardt
2012-05-10  5:23                 ` ytomino
2012-05-09  9:29           ` ytomino
2012-05-10  0:58             ` Randy Brukardt
2012-05-10  4:26               ` ytomino
2012-05-15  6:09                 ` Randy Brukardt
2012-05-15 20:17                   ` ytomino
2012-05-16  0:01                     ` Randy Brukardt
2012-05-15 22:12               ` Simon Wright
2012-05-16  7:14                 ` Dmitry A. Kazakov
2012-05-09  8:05       ` ytomino
2012-05-09 11:03         ` ytomino
replies disabled

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