Doug Lea 談 Synchronization and the Java Memory Model
主要是討論同步和Java內(nèi)存模型之間的關(guān)系,講的原理,從多線程處理產(chǎn)生的問(wèn)題出發(fā),引導(dǎo)出同步的三個(gè)需要處理的問(wèn)題:原子性,可見(jiàn)性,順序性。
Atomicity
Which instructions must have indivisible effects. For purposes of the model, these rules need to be stated only for simple reads and writes of memory cells representing fields - instance and static variables, also including array elements, but not including local variables inside methods.
Visibility
Under what conditions the effects of one thread are visible to another. The effects of interest here are writes to fields, as seen via reads of those fields.
Ordering
Under what conditions the effects of operations can appear out of order to any given thread. The main ordering issues surround reads and writes associated with sequences of assignment statements.
講的特別棒,雖然英文吃力,但是有所得。
然后 Lea 還特別講了下 Java 關(guān)鍵字 Volatile,用到的場(chǎng)景:
The field need not obey any invariants with respect to others.
Writes to the field do not depend on its current value.
No thread ever writes an illegal value with respect to intended semantics.
The actions of readers do not depend on values of other non-volatile fields.