multi-threaded programs Authors: K. Rustan Leino, P. Mller Speaker: - - PowerPoint PPT Presentation

multi threaded programs
SMART_READER_LITE
LIVE PREVIEW

multi-threaded programs Authors: K. Rustan Leino, P. Mller Speaker: - - PowerPoint PPT Presentation

A Basis for Verifying multi-threaded programs Authors: K. Rustan Leino, P. Mller Speaker: Martin Lanter 1 Challenges in multi-threading Fine-grained locking Thread-local and shared objects Distinguish between read and write access


slide-1
SLIDE 1

A Basis for Verifying multi-threaded programs

Authors: K. Rustan Leino, P. Müller Speaker: Martin Lanter

1

slide-2
SLIDE 2

Challenges in multi-threading

  • Fine-grained locking
  • Thread-local and shared objects
  • Distinguish between read and write access
  • Prevent Deadlocks

– Changable locking order

  • Concurrent programs/data structures must be

implemented correctly

2

slide-3
SLIDE 3

Verifying multi-threaded programs

  • Fine grained locking is hard to get right
  • Verify against contracts

– no deadlocks – no data races

3

Chalice Boogie Verifier

slide-4
SLIDE 4

Permissions

  • Between 0 and 100%
  • Permission Holder

– Threads – Monitors – System

  • acc(f, n): n% permission for object f
  • rd(f): infinitesimal permissions for object f

4

slide-5
SLIDE 5

Permissions

  • Obtain Permission by

– Creating a new object (100%) – Acquire an object's monitor (Invariant) – Be forked from another thread (Precond.) – Join another thread (Postcond.)

5

slide-6
SLIDE 6

Contracts with Permissions

int apple; int lemon; void foo() requires acc(apple) ensures acc(lemon) { apple = 5; bar(); lemon = 7; ... }

6

void bar() requires rd(apple) ensures rd(apple) ∧ acc(lemon) { ... }

slide-7
SLIDE 7

Sorted Linked List

val sum next Node: μ: monitor's position in locking order

7

slide-8
SLIDE 8

Sorted Linked List

  • 1

19 4 15 6 9 9 val: sum:

Node's invariant: a) acc(next, 100) ∧ rd(val) b) next ≠ null → rd(next.val) ∧ val ≤ next.val c) next ≠ null → acc(next.sum, 50) ∧ sum = next.val + next.sum d) acc(sum, 50) ∧ (next = null → sum = 0) e) acc(μ, 50) ∧ (next ≠ null → acc(next.μ, 50) ∧ μ next.μ)

8

slide-9
SLIDE 9

Insert x=7

  • 1

19 4 15 6 9 9 val: sum:

invariant head ≠ null ∧ acc(head) ∧ acc(head.sum, 50)

void Insert(x) requires rd(μ) ∧ maxlock ⊂ μ ∧ 0 ≤ x; ensures rd(μ) ∧ maxlock ⊂ μ ∧ head.sum = old(head.sum) + x; { ...

9

head

slide-10
SLIDE 10

Insert x=7

  • 1

19 4 15 6 9 9 val: sum:

acquire this; Node p = head; acquire p; p.sum = p.sum + x; release this; ...

10

head p

slide-11
SLIDE 11

Insert x=7

  • 1

26 4 15 6 9 9 val: sum:

acquire this; Node p = head; acquire p; p.sum = p.sum + x; release this; ...

11

p

slide-12
SLIDE 12

Insert x=7

  • 1

26 4 15 6 9 9 val: sum:

while (p.next ≠ null ∧ p.next.val < x) // loop invariant { Node nx = p.next; acquire nx; nx.sum = nx.sum + x; release p; p = nx; } ...

12

p

slide-13
SLIDE 13

Insert x=7

  • 1

26 4 22 6 9 9 val: sum:

while (p.next ≠ null ∧ p.next.val < x) // loop invariant { Node nx = p.next; acquire nx; nx.sum = nx.sum + x; release p; p = nx; } ...

13

p p

slide-14
SLIDE 14

Insert x=7

  • 1

26 4 22 6 16 9 val: sum:

while (p.next ≠ null ∧ p.next.val < x) // loop invariant { Node nx = p.next; acquire nx; nx.sum = nx.sum + x; release p; p = nx; } ...

14

p p

slide-15
SLIDE 15

Insert x=7

15

  • 1

26 4 22 6 16 9 val: sum:

... Node t = new Node(x); t.sum = p.next.val + p.next.sum; t.next = p.next; share t between p and p.next; p.next = t; release p; } // Insert(x)

7 9 p t

slide-16
SLIDE 16

Verification

  • Permission: (p,n)
  • P[f]: Permission for location f
  • CanRead(f) ≡ let (p,n) = P[f] in p > 0 ∨ n > 0
  • CanWrite(f) ≡ let (p,n) = P[f] in p = 100 ∧ n = 0

16

slide-17
SLIDE 17

Field Access

17

slide-18
SLIDE 18

Acquiring and Releasing

18

slide-19
SLIDE 19

Exhale and Inhale

19

slide-20
SLIDE 20

Conclusion

  • Verification against contracts
  • Verification methodology

– No data races – No deadlocks – Fine-grained locking – Sharing and unsharing of objects – Expressive

  • Future work: Formal proof of soundness

20

slide-21
SLIDE 21

Personal Opinion

  • Complicated
  • Great for critical datastructures

21

slide-22
SLIDE 22

22

slide-23
SLIDE 23

Variables

  • acc(f, n): n% permission for object f
  • rd(f): infinitesimal permissions for object f
  • μ: lock position in locking order
  • u ⊂ v: u's monitor position is strictly less than v
  • share, unshare: Functions to share objects between threads
  • Inhale(J): overtake permissions granted by invariant J
  • Exhale(J): hand over permissions granted by invariant J
  • held: true if a thread has acquired an objects monitor
  • reorder: reorder monitor position between others
  • 𝑞 : list of monitors
  • maxlock: maximum position of acquired monitors
  • ⊥: bottom monitor position
  • havoc: assigns an arbitrary value to be constrained by following assume

23

slide-24
SLIDE 24

Additional Slides

slide-25
SLIDE 25

Additional Slides

25 25