该链接提供了允许合法执行的示例.请参阅第26页第4.8.1
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.79.629&rep=rep1&type=pdf节.
这个例子是
Initially,x = y = 0
Thread 1 Thread 2
r1 = x; r2 = y;
y = 1; x = r2;
r1 == r2 == 1 is a legal behavior
从纸上,
We wish the action r2 = y to see the value 1. C 1 cannot contain this action seeing this value: neither write to y had been committed. C 2 may contain this action; however,the read of y must return 0 in E 2 ,because of Rule 6. Execution E 2 is therefore identical to E 1
In E 3 ,by Rule 7, r2 = y can see any conflicting write that occurs in C 2 (as long as that write is happens-before consistent). This action can now see the write of 1 to y in Thread 1,which was committed in C 1 . We commit one additional action in C 3 : a write of 1 to x by x = r2 .
我们不能提交r2 = y,其中y的值是1,因为y的读取将根据规则6返回0.但是根据E3中下一个提交周期中的文章,r2 = y可以看到值y = 1在Thread1中提交. 我怀疑是执行E3提交r2 = y还应该满足规则6并且应该只看到它之前发生的值,即x = 0.为什么在E2中由于规则6而提交r2 = y,y只能将y值读为0但在E3中提交r2 = y时,y可以读取在Thread1中写入的y = 1?
解决方法
最重要的是要注意的是规则7允许在Ci中执行的读取在Ei中看到的不同写入比在E中看到的那样.但是,薛定谔的读取必须尽早解决.规则5确保这样的读取必须在Ei 1中看到与E中相同的写入.
因此,如果您希望读取看到赛车写入,则不能在提交这两者的同一执行中进行.您需要等待下一次执行,并且您需要确保赛车写入不会违反发生 – 在排序之前(在我们的示例中,主要是在y = 0和r2 = y的排序之前发生).
所以你在C2中提交读取r2 = y,在E2中它只看到写入y = 0,因为写入发生在它之前,但在E3中,r2 = y可以看到它无法建立的赛车写入 – 之前.
附:这篇推理在论文中解释为读r1 = x以下几句:
C4,as part of E4,contains the read r1 = x ; it still sees 0,because of Rule 6. In our final execution E = E5,however,Rule 7 allows r1 = x to see the write of 1 to x that was committed in C3.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|