19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

21.4.1 Dynamic Program Order<br />

Much of the definition of dynamic program order is given in the descriptions of individual expressions in Chapter 13.<br />

It is important to understand that dynamic program order represents a conceptual, naive view of the order of operations<br />

in an execution; this naive view is used to define the more permissive memory order permitted by the memory model.<br />

Dynamic program order is a partial order, rather than a total order; in most cases operations in different threads will<br />

not be ordered with respect to one another. <strong>The</strong>re is an important exception: there is an ordering dependency among<br />

threads when a thread starts or must be complete.<br />

An expression is ordered in dynamic program order after any expression it dynamically contains, with one exception: a<br />

spawn expression is dynamically ordered before any subexpression of its body. <strong>The</strong> body of the spawn is dynamically<br />

ordered before any point at which the spawned thread object is observed to have completed.<br />

Only expressions whose evaluation completes normally occur in dynamic program order, unless the expression is<br />

“directly responsible” for generating abrupt termination. Examples of the latter case are throw and exit expressions<br />

and division by zero. In particular, when the evaluation of a subexpression of an expression completes abruptly,<br />

causing the expression itself to complete abruptly, the containing expression does not occur in dynamic program<br />

order. A label block is ordered after an exit that targets it. <strong>The</strong> expressions in a catch clause whose try block<br />

throws a matching exception are ordered after the throw and before any expression in the finally clause. If the<br />

catch completes normally, the try block as a whole is ordered after the expressions in the finally clause. For<br />

this reason, when we refer to the place of non-spawn expression in dynamic program order, we mean the expression<br />

or any expression it dynamically contains.<br />

For any construct giving rise to implicit threads—tuple evaluation, function or method call, or the body of an expression<br />

with generators such as for —there is no ordering in dynamic program order between the expression executed<br />

in each thread in the group. <strong>The</strong>se subexpressions are ordered with respect to expressions which precede or succeed<br />

the group.<br />

When a function or method is called, the body of the function or method occurs dynamically after the arguments and<br />

function or receiver; the call expression is ordered after the body of the called function or method.<br />

For conditional expressions such as if , case , and typecase , the expression being tested is ordered dynamically<br />

before any chosen branch. This branch is in turn ordered dynamically before the conditional expression itself.<br />

Iterations of the body of a while loop are ordered by dynamic program order. Each evaluation of the guarding<br />

predicate is ordered after any previous iteration and before any succeeding iteration. <strong>The</strong> while loop as a whole is<br />

ordered after the final evaluation of the guarding predicate, which yields false .<br />

An iteration of the body of a for loop, and each evaluation of the body expression in a comprehension or big operator,<br />

is ordered after the generator expressions.<br />

21.4.2 Memory Order<br />

Memory order gives a total order on all memory accesses in a program execution. A read obtains the value of the most<br />

recent prior write to the identical location in memory order. In this section we describe the constraints on memory<br />

order, guided by dynamic program order. We can think of these constraints as specifying a partial order which must<br />

be respected by memory order. <strong>The</strong> simplest constraint is that accesses certainly to the same location must respect<br />

dynamic program order. Apparently disjoint accesses need not respect dynamic program order, but an initializing<br />

write must be ordered before all other accesses to the identical location in program order.<br />

Accesses in distinct (non-nested) atomic expressions respect dynamic program order. Given an atomic expression,<br />

we divide accesses into four classes:<br />

1. Components, dynamically contained within the atomic expression.<br />

160

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

Saved successfully!

Ooh no, something went wrong!