简体   繁体   English

没有线性化点的方法是否总是无法线性化?

[英]Is a method with no linearization points always not linearizable?

If you can definitely prove that a method has no linearization points, does it necessarily mean that that method is not linearizable? 如果您可以肯定地证明某方法没有线性化点,是否一定意味着该方法不可线性化? Also, as a sub question, how can you prove that a method has no linearizatioon points? 另外,作为一个子问题,如何证明方法没有线性化点?

To build upon the answers described above, a method can be described as linearizable. 为了建立上述答案, 可以将一种方法描述为可线性化的。 As referenced in the book that djoker mentioned: http://www.amazon.com/dp/0123705916/?tag=stackoverfl08-20 正如djoker提到的书中所提到的: http ://www.amazon.com/dp/0123705916/?tag=stackoverfl08-20

on page 69, exercise 32, we see 在第69页的练习32中,我们看到

在此处输入图片说明

It should be noted that enq() is indeed a method, that is described as possibily being linearizable/not linearizable. 应当注意,enq()确实是一种方法,被描述为可能线性化/不可线性化。

Proving that there are linearizable points comes down to finding if there are examples that can break linearizability. 证明存在线性化点归结为寻找是否存在可能破坏线性化的示例。 If you make the assumption that various read/write memory operations in a method are linearizable, and then prove by contradiction that there are non-linearizable situations that result from such an assumption, you can declare that the previously mentioned read/write operation is not a valid linearization point. 如果您假设某个方法中的各种读/写存储操作是可线性化的,然后通过矛盾证明这种假设导致了某些不可线性化的情况,则可以声明前面提到的读/写操作不是有效的线性化点。

Take, for example, the following enq()/deq() methods, assuming they are part of a standard queue implementation with head/tail pointers thaand a backing array "arr": 以下面的enq()/ deq()方法为例,假设它们是标准队列实现的一部分,其中头/尾指针为tha,后备数组为“ arr”:

public terribleQueue(){
  arr = new T[10];
  tail = 0;
  head = 0;
}

void enq(T x){
  int slot = tail;
  arr[slot] = x;
  tail = tail + 1;
}

T deq(){
  if( head == tail ) throw new EmptyQueueException();
  T temp = arr[head];
  head = head + 1;
  return temp;
}  

In this terrible implementation, we can easily prove, for example, that the first line of enq is not a valid linearization point, by assuming that it is a linearization point, and then finding an example displaying otherwise, as seen here: 在这个可怕的实现中,例如,我们可以轻松地证明enq的第一行不是有效的线性化点,方法是假定它线性化点,然后找到一个显示其他示例,如下所示:

Take the example two threads, A and B, and the example history: 以示例两个线程A和B以及示例历史记录为例:

A: enq( 1 )
A: slot = 0
B: enq( 2 )
B: slot = 0

(A and B are now past their linearization points, therefore we are not allowed to re-order them to fit our history) (A和B现在已经超过了它们的线性化点,因此我们不允许重新排序它们以适应我们的历史)

A: arr[0] = 1
B: arr[0] = 2
A: tail = 1
B: tail = 2

C: deq()
C: temp = arr[0] = 2
C: head = 1
C: return 2

Now we see that because of our choice of linearization point (which fixes the order of A and B), this execution will be impossible make linearizable, because we cannot make C's deq return 1, no matter where we put it. 现在我们看到,由于我们选择了线性化点(固定了A和B的顺序),因此无法执行线性化此执行,因为无论将C的deq置于何处,都无法使其返回1。

Kind of a long winded answer, but I hope this helps 答案很长,但是我希望这会有所帮助

If you can definitely prove that a method has no linearization points, does it necessarily 
mean that that method is not linearizable?

Firstly, linearizability is not property of a method, it is property of execution sequence. 首先,线性化不是方法的属性,而是执行序列的属性。

how can you prove that a method has no linearizatioon points?

It depends on the execution sequence whether we are able to find linearization point for the method or not. 是否能够找到该方法的线性化点取决于执行顺序。

For example, we have the below sequence, for thread A on a FIFO queue. 例如,对于FIFO队列中的线程A,我们具有以下序列。 t1, t2, t3 are time intervals. t1,t2,t3是时间间隔。

A.enq(1) A.enq(2) A.deq(1) A.enq(1)A.enq(2)A.deq(1)
t1 t2 t3 t1 t2 t3

We can choose linearization points(lp) for first two enq methods as any points in time interval t1 and t2 respectively, and for deq any point in t3. 对于前两个enq方法,我们可以分别选择线性化点(lp)作为时间间隔t1和t2中的任何点,对于deq可以选择t3中的任何点。 The points that we choose are lp for these methods. 对于这些方法,我们选择的要点是lp。

Now, consider a faulty implementation 现在,考虑一个错误的实现

A.enq(1) A.enq(2) A.deq(2) A.enq(1)A.enq(2)A.deq(2)
t1 t2 t3 t1 t2 t3

Linerizability allows lp to respect the real-time ordering. Linerizability允许lp遵守实时订购。 Therefore, lp of the methods should follow the time ordering ie t1 < t2 < t3. 因此,这些方法的lp应遵循时间顺序,即t1 <t2 <t3。 However, since our implementation is incorrect, we cannot clearly do this. 但是,由于我们的实现不正确,因此我们无法明确地做到这一点。 Hence, we cannot find linearization point for the method A.deq(2), in turn our seq. 因此,我们无法找到方法A.deq(2)的线性化点,进而无法找到我们的序列。 too in not linerizable. 太不能衬里了。

Hope this helps, if you need to know more you can read this book: http://www.amazon.com/Art-Multiprocessor-Programming-Maurice-Herlihy/dp/0123705916 希望这对您有所帮助,如果您需要了解更多信息,可以阅读本书: http : //www.amazon.com/Art-Multiprocessor-Programming-Maurice-Herlihy/dp/0123705916

This answer is based on me reading about linearizability on wikipedia for the first time, and trying to map it to my existing understanding of memory consistency through happens-before relationships. 这个答案是基于我第一次阅读有关Wikipedia的线性化,并试图通过先发生后关联将其映射到我对内存一致性的现有理解。 So I may be misunderstanding the concept. 因此我可能会误解这个概念。

If you can definitely prove that a method has no linearization points, does it necessarily mean that that method is not linearizable? 如果您可以肯定地证明某方法没有线性化点,是否一定意味着该方法不可线性化?

It is possible to have a scenario where shared, mutable state is concurrently operated on by multiple threads without any synchronization or visibility aids, and still maintain all invariants without risk of corruption. 可能发生这样的情况:共享的可变状态由多个线程同时操作,而没有任何同步或可见性辅助,并且仍然保持所有不变量而没有损坏的风险。

However, those cases are very rare. 但是,这些情况很少见。

how can you prove that a method has no linearizatioon points? 如何证明方法没有线性化点?

As I understand linearization points, and I may be wrong here, they are where happens-before relationships are established between threads. 据我了解线性化点,在这里我可能是错的,它们是在线程之间建立关系之前发生的地方。 If a method (recursively through every method it calls in turn) establishes no such relationships, then I would assert that it has no linearizatioon points. 如果一个方法(依次递归调用的每个方法)没有建立这样的关系,那么我会断言它没有线性化点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM