Refe开发者_如何学JAVAr to the following program from the JLS.
the explanation of the program is at the end of this section: http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5
i can understand that r1 will be 1, but what is the value of r2. Does the write of x happens-before r2's read to x makes the r2=1?
since x is not synced, it could be in local memory and r2 can be 0?? I am not clear on this about the effect of happens-before order.
According to Happens-before Order ( If hb(x, y) and hb(y, z), then hb(x, z) ), we have hb(x=1, y=1), hb(y=1, r1=y), hb(r1=y, r2=x), therfore hb(x=1, r2=x). So r2=1.
精彩评论