The Java Memory Model
While we were never explicit about it throughout this chapter, we have actually defined most of the JMM. What is a memory model in the first place?
A language memory model is a specification that describes the circumstances under which a write to a variable becomes visible to other threads. You might think that a write to a variable v changes the corresponding memory location immediately after the processor executes it, and that other processors see the new value of v instantaneously. This memory consistency model is called sequential consistency.
As we already saw in the ThreadSharedStateAccessReordering example, sequential consistency has little to do with how processors and compilers really work. Writes rarely end up in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access