简体   繁体   中英

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:

  • 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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