java 鱼刺图_Java JSR-133 因果关系中 6.3.1的例子为什么会出现r1==r2==1呢?

JSL8 657页有说明。Since this program is correctly synchronized, the only behaviors we can allow are

sequentially consistent behaviors. However, there is an execution of this program that is

happens-before consistent, but not sequentially consistent:

r1 = x; // sees write of x = 1

y = 1;

r2 = y; // sees write of y = 1

x = 1;

This result is happens-before consistent: there is no happens-before relationship that

prevents it from occurring. However, it is clearly not acceptable: there is no sequentially

consistent execution that would result in this behavior. The fact that we allow a read to see a write that comes later in the execution order can sometimes thus result in unacceptable behaviors.

意思是说,hp约束并没有限制r1不能读取到x=1这个值。

所以在指令优化的时候,代码可能被优化成这样。

Thread 1 Thread 2

y = 1; x = 1;

r1 = x; r2 = y;

if (false); if (false);

因为在T1内部,y等于什么值和r1一点关系都没有,同理T2内部,x等于什么值和r2一点关系都没有。怎么执行都不违反hp约束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值