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.5 Happens-before Order THREADS AND LOCKS<br />

564<br />

accesses. However, in execution (b), there is no happens-before ordering between the conflicting<br />

accesses to X. Because of this, the program is not correctly synchronized.<br />

Thread 1<br />

X = 1<br />

Lock M1<br />

Y = 1<br />

Unlock M1<br />

Thread 2<br />

Lock M1<br />

r1 = Y<br />

Unlock M1<br />

DRAFT<br />

r2 = X<br />

(a) Thread 1 acquires lock first; Accesses to X are ordered by happens-before

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

Saved successfully!

Ooh no, something went wrong!