I have some regarding the order of the program and how this affects reordering in JMM.
In the Java memory model, program order (po) is defined as the general order of actions in each thread in the program. According to JLS , this leads to the occurrence-before (hb) edges:
If x and y are the actions of the same thread, and x is up to y in the programming order, then hb (x, y) (i.e., x occurs before y ).
So, for a simple P program:
initially, x = y = 0 T1 | T2 -----------|----------- 1. r1 = x | 3. r2 = y 2. y = 1 | 4. x = r2
I think po (1, 2) and po (3, 4). Thus, hb (1, 2) and hb (3, 4).
Now suppose I wanted to reorder some of these statements, giving me P ':
initially, x = y = 0 T1 | T2 -----------|----------- 2. y = 1 | 3. r2 = y 1. r1 = x | 4. x = r2
In accordance with this article, we can reorder any two neighboring operators (for example, 1 and 2), provided that reordering does not eliminate any transitive events - before edges in any real execution. However, since hb is determined (partially) by po, and po is the complete order over the actions of the stream, it seems to me that it would be impossible to reorder any two statements without breaking hb, so P 'is not a legal transformation.
My questions:
- Do I understand po and hb correctly, and have I correctly defined po and hb relative to the above program P?
- Where is my understanding about reordering regarding hb failure?
java multithreading concurrency java-memory-model
Kumalh
source share