开发者

How will the following java program run, in the ""happens-before" order example?

开发者 https://www.devze.com 2023-03-17 18:59 出处:网络
Refe开发者_如何学JAVAr to the following program from the JLS. the explanation of the program is at the end of this section:

Refe开发者_如何学JAVAr to the following program from the JLS.

How will the following java program run, in the ""happens-before" order example?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消