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:
- an int v
- a method read(): returns the value of v
- a method cas(expected, update): takes 2 arguments: an
expected
value and anupdate
value. If the currentv
value is equal to the expected value, then it is replaced by the update value; otherwise, the value is left unchanged. The method call returns a Boolean indicating whether the valuev
changed.