[英]How to prove that a concurrent object is linearizable?
Is there a method to prove if an object is linearizable?有没有一种方法可以证明对象是否可线性化? For example for the code below.
例如对于下面的代码。 How can I prove that the counter is linearizable?
如何证明计数器是可线性化的?
here is the algorithm of the shared counter:这是共享计数器的算法:
CompareAndSet R = new CompareAndSet(0);
increment() {
Boolean ret; int r;
repeat r = R.read(); ret = R.cas(r, r+1)
until(ret = true)
return
}
read() {
return R.read();
}
CompareAndSet is an object that contains: CompareAndSet 是一个包含以下内容的对象:
expected
value and an update
value.expected
和一个update
值。 If the current v
value is equal to the expected value, then it is replaced by the update value;v
值等于期望值,则将其替换为更新值; otherwise, the value is left unchanged.v
changed.v
是否改变。Generally speaking, you need to show that for each method that mutates the concurrent object, there is a "linearization point" where the method takes effect.一般来说,你需要证明,对于每个对并发对象进行变异的方法,都有一个“线性化点”,该方法在该点生效。
For your counter, it is trivial.对于你的柜台来说,这是微不足道的。 If we assume that
R.cas()
is performed atomically, then your linearization point in increment()
is when R.cas()
succeeds in updating the value.如果我们假设
R.cas()
是原子执行的,那么increment()
线性化点就是R.cas()
成功更新值的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.