10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

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.

17.4.1 Shared Variables THREADS AND LOCKS<br />

558<br />

Each time the evaluation of thread t generates an inter-thread action, it must<br />

match the inter-thread action a of t that comes next in program order. If a is a read,<br />

then further evaluation of t uses the value seen by a as determined by the memory<br />

model.<br />

This section provides the specification of the <strong>Java</strong> programming language<br />

memory model except for issues dealing with final fields, which are described in<br />

§17.5.<br />

17.4.1 Shared Variables<br />

Memory that can be shared between threads is called shared memory or heap<br />

memory.<br />

All instance fields, static fields and array elements are stored in heap memory.<br />

In this chapter, we use the term variable to refer to both fields and array elements.<br />

Local variables (§14.4), formal method parameters (§8.4.1) or exception handler<br />

parameters are never shared between threads and are unaffected by the memory<br />

model.<br />

Two accesses to (reads of or writes to) the same variable are said to be conflicting<br />

if at least one of the accesses is a write.<br />

17.4.2 Actions<br />

An inter-thread action is an action performed by one thread that can be<br />

detected or directly influenced by another thread. <strong>The</strong>re are several kinds of interthread<br />

action that a program may perform:<br />

• Read (normal, or non-volatile). Reading a variable.<br />

• Write (normal, or non-volatile). Writing a variable.<br />

• Synchronization actions, which are:<br />

DRAFT<br />

◆ Volatile read. A volatile read of a variable.<br />

◆ Volatile write. A volatile write of a variable.<br />

◆ Lock. Locking a monitor<br />

◆ Unlock. Unlocking a monitor.<br />

◆ <strong>The</strong> (synthetic) first and last action of a thread<br />

◆ Actions that start a thread or detect that a thread has terminated, as<br />

described in §17.4.4.

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

Saved successfully!

Ooh no, something went wrong!