19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

of apparently disjoint (or simply disjoint) object and field references. If two references are not disjoint, we say they<br />

are certainly the same, or just the same. By contrast, we say object references are identical if they refer to the same<br />

object, and distinct otherwise. Accesses to fields reached via apparently disjoint object references may be reordered<br />

(except an initializing write is never reordered with respect to other accesses to the identical location).<br />

Distinct references are always disjoint. Two identical references are apparently disjoint if they are obtained from any<br />

of the following locations:<br />

• distinct parameters of a single function call<br />

• distinct fields<br />

• a parameter and a field<br />

• identically named fields read from apparently disjoint object references<br />

• distinct reads of a single location for which there may be an interposing write<br />

When comparing variables defined in different scopes, these rules will eventually lead to reads of fields or to reads of<br />

parameters in some common containing scope.<br />

We extend this to field references as follows: two field references are apparently disjoint if they refer to distinct fields,<br />

or they refer to identically named fields read from apparently disjoint object references.<br />

Consider the following example:<br />

f(x : Z64[2], y : Z64[2]) : Z64 = do<br />

x 0 := 17<br />

y 0 := 32<br />

end<br />

Here x and y in f are apparently disjoint; the writes may be reordered, so the call f(a, a) may assign either 17 or 32<br />

to a 0 .<br />

A similar phenomenon occurs in the following example:<br />

g(x : Z64[2], y : Z64[2]) : Z64 = do<br />

x 0 := 17<br />

y 0<br />

end<br />

Again x and y are apparently distinct in g , so the write to x 0 and the read of y 0 may be reordered. <strong>The</strong> call g(a, a)<br />

will assign 17 to a 0 but may return either the former value of a 0 or 17.<br />

It is safe to read an object through apparently disjoint references:<br />

h(x : Z64[2], y : Z64[2]) : Z64 = do<br />

u : Z64 = x 0<br />

v : Z64 = y 0<br />

u + v<br />

end<br />

A call to h(a, a) will read a 0 twice without ambiguity. Note, however, that the reads may still be reordered, and if<br />

a 0 is written in parallel by another thread this reordering can be observed.<br />

If necessary, atomic expressions can be used to order disjoint field references:<br />

f ′ (x : Z64[2], y : Z64[2]) : () = do<br />

atomic x 0 := 17<br />

atomic y 0 := 32<br />

end<br />

158

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!