Java memory model actions

I am trying to understand the Java Memory Model , but I have problems with the actions. I understand the definition of an action as <t, k, v, u>, but I don’t quite understand how the program is divided into actions, and how abstract these actions are.

My first assumption was that actions are atomic. var1 = var2will be divided into two actions - reading var2and writing to var1, but the example here assumes that var1 = var2this is an action. Therefore, each action corresponds to a statement in the source code.

How does this work with the if statement? For example, if we had if(r1 == r2 && r3 == r4) { ... }, would the whole expression be a single action or split into several actions (and if so, how do the corresponding actions remain “connected” as the if statement)?

+4
source share
1 answer

Actions are defined in JLS 17.4.2 , which focuses on "cross-thread actions:"

An action between threads is an action performed by one thread that can be detected or directly depends on another thread .... This specification only applies to actions between threads.

( ), .

var1 = var2 , var1 var2. , ( var2 var). - , , - , , .

, var2 - , var1 - , var2 — , , .

, if (r1 == r2 && r3 == r4) 4 : , . == && , , .

+3

Source: https://habr.com/ru/post/1606521/


All Articles