proving linearizability using partial orders
play

Proving Linearizability Using Partial Orders Artem Khyzha Mike Dodds - PowerPoint PPT Presentation

Proving Linearizability Using Partial Orders Artem Khyzha Mike Dodds Alexey Gotsman Matthew Parkinson The Kent Concurrency Workshop July 22 nd 2016 In this talk Algorithms posing challenges for the linearization points method: the


  1. Proving Linearizability Using Partial Orders Artem Khyzha Mike Dodds Alexey Gotsman Matthew Parkinson The Kent Concurrency Workshop July 22 nd 2016

  2. In this talk • Algorithms posing challenges for the linearization points method: • the Herlihy-Wing queue • the Optimistic Set / Lazy List • the Timestamp Queue

  3. In this talk • Algorithms posing challenges for the linearization points method: • the Herlihy-Wing queue • the Optimistic Set / Lazy List • the Timestamp Queue

  4. Linearizability for every concrete history e(‘a’) d(?) t 1 e(‘d’) e(‘b’) t 2 e(‘c’) t 3 find a linearization e(‘b’) e(‘a’) e(‘c’) d(?) e(‘d’)

  5. Linearizability for every concrete history e(‘a’) d(?) t 1 e(‘d’) e(‘b’) t 2 e(‘c’) t 3 find a linearization e(‘b’) e(‘a’) e(‘c’) d(?) e(‘d’) Standard proof technique: linearization points

  6. Linearization points for every concrete history e(‘a’) d(?) t 1 e(‘d’) e(‘b’) t 2 e(‘c’) t 3 find a linearization * e(‘b’) e(‘a’) e(‘c’) d(?) e(‘d’) * ? = ‘b’

  7. Linearization points concrete history e(‘a’) d(?) t 1 e(‘d’) e(‘b’) t 2 e(‘c’) t 3 * • by the moment (*) we still may not know where the linearization points of e(‘a’) and e(‘b’) are

  8. The TS Queue t 1 t 2 t 3 • each thread has its own pool ‘b’ ‘c’ ‘a’ (2,3) (2,4) (1,1) ‘d’ (3,4) • pool is an abstract sequence • (single producer multiple consumers)

  9. The TS Queue t 1 t 2 t 3 e(‘a’) d(?) t 1 ‘b’ ‘c’ ‘a’ e(‘d’) e(‘b’) (2,3) (2,4) (1,1) t 2 ‘d’ (3,4) e(‘c’) t 3

  10. The TS Queue t 1 t 2 t 3 ‘b’ ‘c’ ‘a’ ts b ts c enqueue(Val v) { ts a ‘d’ ts := newTimestamp(); ts d insert(this_thread, v, ts); }

  11. The TS Queue Val dequeue() { do { t 1 t 2 t 3 for each pool do { get the front node; ‘b’ ‘c’ ‘a’ ts b ts c ts a update the candidate ‘d’ for removal; ts d } if (there is a candidate) try removing it and returning its value; } while (true); }

  12. The TS Queue Val dequeue() { do { t 1 t 2 t 3 for each pool do { get the front node; ‘b’ ‘c’ ‘a’ ts b ts c ts a update the candidate ‘d’ for removal; ts d } if (there is a candidate) try removing it and returning its value; } while (true); }

  13. The TS Queue Val dequeue() { do { t 1 t 2 t 3 for each pool do { get the front node; ‘b’ ‘c’ ‘a’ ts b ts c ts a update the candidate update the candidate ‘d’ for removal; for removal; ts d } if (there is a candidate) try removing it and returning its value; } while (true); by choosing the } smallest timestamp

  14. Timestamps t 1 t 2 t 3 e(‘a’) d(?) t 1 ‘b’ ‘c’ ‘a’ e(‘d’) e(‘b’) (1,2) (3,3) (1,2) t 2 ‘d’ (4,4) e(‘c’) t 3 • the connection with the real-time order • e1 —rt—> e2 ==> timestamp(e1) < timestamp(e2)

  15. Timestamps Val dequeue() { do { t 1 t 2 t 3 for each pool do { get the front node; ‘b’ ‘c’ ‘a’ (1,2) (3,3) (1,2) update the candidate ‘d’ for removal; (4,4) } if (there is a candidate) try removing it and returning its value; the smallest } while (true); timestamp belongs to } the “oldest” element

  16. Timestamps t 1 t 2 t 3 e(‘a’) d(‘?’) t 1 ‘b’ ‘c’ ‘a’ e(‘d’) e(‘b’) (1,2) (3,3) (1,2) t 2 ‘d’ (4,4) e(‘c’) t 3 • problem: the order on enqueues may be impossible to determine till they are dequeued

  17. Our technique • We alter the standard proof technique to support late choice via partial orders • Our proof technique is implemented in a logic, should be sound • Examples: the TS queue, the Herlihy-Wing queue, the Optimistic Set

  18. Abstract histories • For each history of a data structure we construct a matching abstract history (instead of a linearization) • An “abstract” history (E, R): • E — a set of events [eid: (tid, op, arg, rval)] • R — a partial order

  19. Abstract histories • For each history of a data structure we construct a matching abstract history (instead of a linearization) • An “abstract” history (E, R) 1. the abstract history extends the real-time order • E — a set of events [eid: (tid, op, arg, rval)] 2. all linearizations meet the sequential spec • R — a partial order • all its linearizations meet the sequential specification

  20. Abstract histories • We prove a number of invariant properties including: • all linearizations meet the sequential spec • for all enqueues e, e’ with values in the data structure: • e —> e’ ==> timestamp(e) < timestamp(e’) • …

  21. Commitment points • Abstract histories are constructed: • by adding new events • by adding more edges into the partial order • by assigning a return value to an event

  22. Commitment points • At the beginning of each operation, a fresh event and real-time order edges are added to the abstract history e(‘a’) d(‘b’) t 1 e(‘b’) t 2 e(‘c’) t 3

  23. Commitment points • At the beginning of each operation, a fresh event and real-time order edges are added to the abstract history e(‘a’) e(‘a’) d(‘b’) t 1 e(‘b’) t 2 [“e(‘a’)” : t1, enq, ‘a’, TODO] e(‘c’) t 3

  24. Commitment points • At the beginning of each operation, a fresh event and real-time order edges are added to the abstract history e(‘a’) e(‘a’) d(‘b’) t 1 e(‘b’) t 2 e(‘b’) e(‘c’) t 3

  25. Commitment points • At the beginning of each operation, a fresh event and real-time order edges are added to the abstract history e(‘a’) e(‘a’) d(‘b’) t 1 e(‘b’) t 2 e(‘b’) e(‘c’) t 3 • events get completed by the end of the operations

  26. Commitment points • At the beginning of each operation, a fresh event and real-time order edges are added to the abstract history e(‘a’) d(?) e(‘a’) d(‘b’) t 1 e(‘b’) t 2 e(‘c’) e(‘b’) e(‘c’) t 3 • edges from the completed events are added

  27. Enqueue’s commitment point enqueue(Val v) { ts := newTimestamp(); atomic { insert(this_thread, v, ts); E(this_event).rval := DONE; G[this_event] := ts; } } • Ghost state G is a map from events and timestamps • Helps to establish a bijection between events and elements of the data structure

  28. Commitment points • The late choice is resolved by a dequeue with the FIFO policy in mind e(‘a’) d(?) e(‘a’) d(‘b’) t 1 e(‘b’) t 2 e(‘c’) e(‘b’) e(‘c’) t 3

  29. Commitment points • The late choice is resolved by a dequeue with the FIFO policy in mind 1. e(‘b’) e(‘a’) d(‘b’) e(‘c’) e(‘a’) d(‘b’) 2. e(‘b’) e(‘a’) e(‘c’) d(‘b’) 3. e(‘a’) e(‘b’) d(‘b’) e(‘c’) 4. e(‘a’) e(‘b’) e(‘c’) d(‘b’) e(‘c’) e(‘b’)

  30. Commitment points • The late choice is resolved by a dequeue with the FIFO policy in mind 1. e(‘b’) e(‘a’) d(‘b’) e(‘c’) e(‘a’) d(‘b’) 2. e(‘b’) e(‘a’) e(‘c’) d(‘b’) 3. e(‘a’) e(‘b’) d(‘b’) e(‘c’) 4. e(‘a’) e(‘b’) e(‘c’) d(‘b’) e(‘c’) e(‘b’)

  31. Commitment points • The late choice is resolved by a dequeue with the FIFO policy in mind 1. e(‘b’) e(‘a’) d(‘b’) e(‘c’) d(‘b’) 2. e(‘b’) e(‘a’) e(‘c’) d(‘b’) e(‘b’) e(‘a’) e(‘c’)

  32. Commitment points • The late choice is resolved by a dequeue with the FIFO policy in mind d(‘b’) d(?) e(‘b’) e(‘a’) e(‘c’)

  33. Dequeue’s commitment point if (there is a candidate enq ) { res := try removing enq ; if (res != FAIL) { E(this_event).rval := res; R := (R U {(enq, this_event)} U {(enq, e’) | the value of e’ is in queue} U {(deq, d’} | d’ is an uncompleted dequeue})+; } }

  34. Acyclicity • Need to prove that ordering by commitment points is possible without breaking acyclicity • Loop invariant — implies that the candidate for removal is the minimal in the partial order • Invariant properties (what holds by construction of the partial order)

  35. The proof • For each history of a data structure we construct a matching abstract history (instead of a linearization) • preserving the real-time order • ensuring that all linearizations meet the sequential specification • constructed with commitment points • Partiality of the order enables delaying the choice of a linearization order

  36. Conclusions • The technique for proving linearizability of algorithms that are challenging with the linearization points method • Examples: the TS queue, the Herlihy-Wing queue, the Optimistic Set • Does not work for the TS stack

Recommend


More recommend