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.

Here the call f(a, a) ends up setting a 0 to 32. Note that simply using a single atomic expression containing one or<br />

both writes is not sufficient; the two writes must be in distinct atomic expressions to be required to occur in order.<br />

When references occur in distinct calling contexts, they are disambiguated at the point of call:<br />

j(x : Z64[2], y : Z64) : () = x 0 := y<br />

k(x : Z64[2]) :() = do<br />

j(x, 17)<br />

j(x, 32)<br />

end<br />

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

j(x, 17)<br />

j(y, 32)<br />

end<br />

Here if we call k(a) the order of the writes performed by the two calls to j is unambiguous, and a 0 is 32 in the<br />

end. By contrast, l(a, a) calls j with two apparently disjoint references, and the writes in these two calls may thus be<br />

reordered.<br />

21.3 Read and Write Atomicity<br />

Any read or write to a location is indivisible. In practical terms, this means that each read operation will see exactly the<br />

data written by a single write operation. Note in particular that indivisibility holds for a mutable location containing<br />

a large value object. It is convenient to imagine that every access to a mutable location is surrounded by an atomic<br />

expression. However, there are a number of ordering guarantees provided by atomic accesses that are not respected<br />

by non-atomic accesses.<br />

21.4 Ordering Dependencies among Operations<br />

<strong>The</strong> <strong>Fortress</strong> memory model is specified in terms of two orderings: dynamic program order and memory order. Dynamic<br />

program order is a partial order between the expressions evaluated in a particular execution of a program. <strong>The</strong><br />

actual order of memory operations in a given program execution is memory order, a total order on all memory operations.<br />

Dynamic program order is used to constrain memory order. However, memory operations need not be ordered<br />

according to dynamic program order; many memory operations, even reads and writes to a single field or array element,<br />

can be reordered. Programmers who adhere to the model in Section 21.2 can expect sequentially consistent<br />

behavior: there will be a global ordering for all memory operations that respects dynamic program order.<br />

Here is a summary of the salient aspects of memory order:<br />

• <strong>The</strong>re is a single memory order which is respected in all threads.<br />

• Every read obtains the value of the immediately preceding write to the identical location in memory order.<br />

• Memory order on atomic expressions respects dynamic program order.<br />

• Memory order respects dynamic program order for operations that certainly access the same location.<br />

• Initializing writes are ordered before any other memory access to the same location.<br />

159

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

Saved successfully!

Ooh no, something went wrong!