Java Reference
In-Depth Information
and can be determined by examining the intra-thread semantics. They are not explicitly dis-
cussed in the memory model.
In non-terminating executions, not all external actions are observable. Non-terminating ex-
ecutions and observable actions are discussed in § 17.4.9 .
17.4.3. Programs and Program Order
Among all the inter-thread actions performed by each thread t , the program order of t is a
total order that reflects the order in which these actions would be performed according to
the intra-thread semantics of t .
A set of actions is sequentially consistent if all actions occur in a total order (the execution
order) that is consistent with program order, and furthermore, each read r of a variable v
sees the value written by the write w to v such that:
w comes before r in the execution order, and
• there is no other write w ' such that w comes before w ' and w ' comes before r in the
execution order.
Sequential consistency is a very strong guarantee that is made about visibility and ordering
in an execution of a program. Within a sequentially consistent execution, there is a total or-
der over all individual actions (such as reads and writes) which is consistent with the order
of the program, and each individual action is atomic and is immediately visible to every
thread.
If a program has no data races, then all executions of the program will appear to be sequen-
tially consistent.
Sequential consistency and/or freedom from data races still allows errors arising from
groups of operations that need to be perceived atomically and are not.
If we were to use sequential consistency as our memory model, many of the compiler
and processor optimizations that we have discussed would be illegal. For example, in
the trace in Table 17.3 , as soon as the write of 3 to p.x occurred, subsequent reads of
that location would be required to see that value.
17.4.4. Synchronization Order
Every execution has a synchronization order . A synchronization order is a total order over
all of the synchronization actions of an execution. For each thread t , the synchronization
order of the synchronization actions (§ 17.4.2 ) in t is consistent with the program order
17.4.3 ) of t .
Search WWH ::




Custom Search