Java Reference
In-Depth Information
plementation of thread t as it would be performed in a single-threaded context, as defined
in the rest of this specification.
Each time the evaluation of thread t generates an inter-thread action, it must match the
inter-thread action a of t that comes next in program order. If a is a read, then further eval-
uation of t uses the value seen by a as determined by the memory model.
This section provides the specification of the Java programming language memory model
except for issues dealing with final fields, which are described in § 17.5 .
The memory model specified herein is not fundamentally based in the object-oriented
nature of the Java programming language. For conciseness and simplicity in our ex-
amples, we often exhibit code fragments without class or method definitions, or ex-
plicit dereferencing. Most examples consist of two or more threads containing state-
ments with access to local variables, shared global variables, or instance fields of an
object. We typically use variables names such as r1 or r2 to indicate variables local to
a method or thread. Such variables are not accessible by other threads.
17.4.1. Shared Variables
Memory that can be shared between threads is called shared memory or heap memory .
All instance fields, static fields, and array elements are stored in heap memory. In this
chapter, we use the term variable to refer to both fields and array elements.
Local variables (§ 14.4 ), formal method parameters (§ 8.4.1 ), and exception handler para-
meters (§ 14.20 ) are never shared between threads and are unaffected by the memory model.
Two accesses to (reads of or writes to) the same variable are said to be conflicting if at least
one of the accesses is a write.
17.4.2. Actions
An inter-thread action is an action performed by one thread that can be detected or directly
influenced by another thread. There are several kinds of inter-thread action that a program
may perform:
Read (normal, or non-volatile). Reading a variable.
Write (normal, or non-volatile). Writing a variable.
Synchronization actions , which are:
Volatile read . A volatile read of a variable.
Volatile write . A volatile write of a variable.
Search WWH ::




Custom Search