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约束。