3

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 an update value. If the current v 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 value v changed.
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Sydney.Ka
  • 175
  • 7

1 Answers1

0

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.

Eric
  • 906
  • 7
  • 13