顺序一致性

时间:2016-10-11 09:28:58

标签: parallel-processing distributed-computing

以下顺序是否一致

P1:W(x)1 R(x)1 ----------------------- R(x)1

P2:W(x)2 ------------- R(x)2 R(x)1

P3:W(x)3 R(x)3 ---------------------- R(x)1

我相信这是顺序一致的,因为各个处理器满足程序顺序

1 个答案:

答案 0 :(得分:0)

不,这不是顺序一致的痕迹。

为了使其顺序一致,应该存在等效的 legal 跟踪,其中每个进程的操作按其程序顺序执行。并且跟踪是 legal 顺序,并且每次读取寄存器X都会返回最后写入的值。

我们可以构建一个 legal 跟踪,但是其中P2和P3的操作与它们的程序顺序不匹配(返回1的读取必须在写入之前重新排序):

P1: W(X, 1)
P1: R(X) → 1
P1: R(X) → 1
P2: R(X) → 1
P3: R(X) → 1
P2: W(X, 2)
P2: R(X) → 2
P3: W(X, 3)
P3: R(X) → 3

试图满足这两个属性我们发现它不可能:

// it doesn't matter where we start really: P1, P2 or P3
// (but with P2 and P3 the seq. consistent part of the trace would be even shorter)
// let's go with P1 
P1: W(X, 1)

// now the next read has to see X=1 so the trace remains legal
P1: R(X) → 1
// and again
P1: R(X) → 1

// no more P1's operations,
// have to chose first op in either P1's or P2's program order
// let's go with P2
P2: W(X, 2)

// now the next read has to see X=2 so the trace remains legal
P2: R(X) → 2 // great!

// at this point there's no operation that would keep the trace legal
// except P3's W(X, 3)
P3: W(X, 3)

// there's only three reads left and the next one should see X=3
P3: R(X) → 3 // yay!

// but the last two reads ruin everything
P2: R(X) → 1 // not seq. consistent! (because isn't legal)
P3: R(X) → 1 // again, not seq. consistent!