但是同步还有另一个方面:正如JMM所指定,它强制实施某些内存可见性规则。
But synchronization also has another aspect: it enforces certain memory visibility rules as specified by the JMM.
注意,在同一个线程的不同方法之间传递对象的引用,永远也不会出现内存可见性问题。
Note that visibility problems never arise when passing references to objects across methods in the same thread.
可见性则更为微妙;它要对付内存缓存和编译器优化的各种反常行为。
Visibility is more subtle; it deals with the vagaries of memory caching and compiler optimizations.
换句话说,这意味着老的内存模型只保证正在读或写的变量的可见性,不保证写入其他变量的可见性。
In other words, this means that the old memory model made promises only about the visibility of the variable being read or written, and no promises about the visibility of writes to other variables.
特别是,内存模型定义了保证内存操作跨线程的可见性的volatile、synchronized和final的语义。
In particular, the memory model defines semantics for volatile, synchronized, and final that make guarantees of visibility of memory operations across threads.
特别是,内存模型定义了保证内存操作跨线程的可见性的volatile、synchronized和final的语义。
In particular, the memory model defines semantics for volatile, synchronized, and final that make guarantees of visibility of memory operations across threads.
应用推荐