A marriage of rely/guarantee & separation logic Viktor V - - PowerPoint PPT Presentation

a marriage of rely guarantee separation logic
SMART_READER_LITE
LIVE PREVIEW

A marriage of rely/guarantee & separation logic Viktor V - - PowerPoint PPT Presentation

A marriage of rely/guarantee & separation logic Viktor V afeiadis MPI - SWS Coarse - grain locking 2 3 5 7 11 13 Coarse - grain locking 2 3 5 7 11 13 Fine - grain locking Pessimistic: lock - coupling 2 3 5 7 11 13 Fine -


slide-1
SLIDE 1

A marriage of rely/guarantee & separation logic

Viktor V afeiadis MPI-SWS

slide-2
SLIDE 2

Coarse-grain locking

2 3 5 7 11 13

slide-3
SLIDE 3

Coarse-grain locking

2 3 5 7 11 13

slide-4
SLIDE 4

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-5
SLIDE 5

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-6
SLIDE 6

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-7
SLIDE 7

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-8
SLIDE 8

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-9
SLIDE 9

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-10
SLIDE 10

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-11
SLIDE 11

2 3 5 7 11 13

Fine-grain locking

Pessimistic: lock-coupling

slide-12
SLIDE 12

2 3 5 7 11 13

Fine-grain locking

Optimistic traversal

slide-13
SLIDE 13

2 3 5 7 11 13

Fine-grain locking

Optimistic traversal

slide-14
SLIDE 14

2 3 5 7 11 13

Fine-grain locking

Optimistic traversal Re-traverse the list OR deletions in two steps Leaks memory: cannot dispose deleted nodes.

slide-15
SLIDE 15

Operations (actions)

Lock Unlock Pessimistic algorithm Add node Delete node

slide-16
SLIDE 16

Optimistic algorithm Lock Unlock Add node Delete node

Operations (actions)

slide-17
SLIDE 17

Fine-grained concurrency

  • Complex concurrency patterns
  • Dynamically allocated data structures
  • Explicit memory deallocation
  • Concurrent libraries: java.util.concurrent

Aim: T ractable reasoning, manual & automatic

slide-18
SLIDE 18

Separation logic

[Reynolds, O’Hearn, et al. 2001+]

slide-19
SLIDE 19

Separation logic (1/3)

e1 e2

empty heap ... a logic for describing the heap

P Q

single cell separation

lseg(x, y)

def

= (x = y ∧ emp) ∨ (∃z v. x → v, z ∗ lseg(z, y)) P, Q ::= e = e′ | P ∧ Q | P ∨ Q | ¬P | ∃x. P | ∀x. P | emp | e → e1, . . . , en | P ∗ Q | P − ∗ Q e :

slide-20
SLIDE 20

Separation logic (2/3)

  • Hoare triples

{precondition} program {postcondition}

  • Rules for commands accessing the heap
  • Frame rule

... a program logic

P Q C R R P Q C

If then {P} C {Q} {P ∗ R} C {Q ∗ R}

slide-21
SLIDE 21

Separation logic (3/3)

... disjoint parallelism If then

P1 Q1 C1 P2 Q2 C2 P1 Q1 P2 Q2 C1C2

and [+ resource invariants] {P1} C1 {Q1} {P2} C2 {Q2} {P1 ∗ P2} C1C2 {Q1 ∗ Q2}

slide-22
SLIDE 22

Introduction to RGSep

Basic concepts

slide-23
SLIDE 23

2 3 5 7 11 13

Local and shared state

Shared Local

6

slide-24
SLIDE 24

Actions

Describe how the shared state changes: (i) by the program & (ii) by its environment Semantics: An action changes the part of the shared state that matches the LHS to something that matches the RHS. The rest of the shared state is not touched. Lock Unlock

slide-25
SLIDE 25

The two roles of actions

  • Guarantee: As annotations to atomic blocks,

they specify what an atomic block does to the shared state They also adjust the boundary between local and shared state

  • Rely: Abstract what all the other threads do to

the shared state

slide-26
SLIDE 26

Effect of an action

2 3 5 7 11 13

Shared Local

6 Lock

slide-27
SLIDE 27

Effect of an action

2 3 5 7 11 13

Shared Local

6 Lock 2 3 5 7 11 13

Shared Local

6

slide-28
SLIDE 28

Effect of an action

2 3 5 7 11 13

Shared Local

6 Lock 2 3 5 7 11 13

Shared Local

6

slide-29
SLIDE 29

Effect of an action

2 3 5 7 11 13

Shared Local

6 Lock 2 3 5 7 11 13

Shared Local

6

slide-30
SLIDE 30

Effect of an action

2 3 5 7 11 13

Shared Local

6 Lock 2 3 5 7 11 13

Shared Local

6

slide-31
SLIDE 31

Effect of an action

2 3 5 7 11 13

Shared Local

6 Lock 2 3 5 7 11 13

Shared Local

6

slide-32
SLIDE 32

Effect of an action

2 3 5 7 11 13

Shared Local

6 Lock 2 3 5 7 11 13

Shared Local

6

slide-33
SLIDE 33

Ownership transfer

Where did this node come from? Where did this node go? Add node Delete node

slide-34
SLIDE 34

Local and shared state

2 3 5 7 11 13

Shared Local

6

Add node

Pessimistic algorithm

slide-35
SLIDE 35

Local and shared state

2 3 5 7 11 13

Shared

6

Local

Add node

Pessimistic algorithm

slide-36
SLIDE 36

Local and shared state

2 3 5 7 11 13

Shared

6

Local

Lock node

Pessimistic algorithm

slide-37
SLIDE 37

Local and shared state

2 3 5 7 11 13

Shared

6

Local

Lock node

Pessimistic algorithm

slide-38
SLIDE 38

Local and shared state

2 3 5 7 11 13

Shared

6

Local

Delete node

Pessimistic algorithm

slide-39
SLIDE 39

Local and shared state

2 3 5 7 11 13

Shared Local

6

Delete node

Pessimistic algorithm

slide-40
SLIDE 40

Local and shared state

2 3 5 7 11 13

Shared Local

6

Now, the node is local; we can safely dispose it. Pessimistic algorithm

slide-41
SLIDE 41

Local and shared state

2 3 5 7 11 13

Shared Local Now, the node is local; we can safely dispose it. Pessimistic algorithm

slide-42
SLIDE 42

Local and shared state

Shared Local

13 2 3 5 7 11 6

Optimistic algorithm

Delete node

slide-43
SLIDE 43

Local and shared state

Shared Local

13 2 3 5 7 11 6

Optimistic algorithm

Delete node

slide-44
SLIDE 44

2 7 11 13 5

Interference:

  • ther threads

A A

3

slide-45
SLIDE 45

2 7 11 13 5

Interference:

  • ther threads

A A

slide-46
SLIDE 46

2 7 11 13 5

Interference:

  • ther threads

12

A A

slide-47
SLIDE 47

2 7 11 13 5

Interference:

  • ther threads

12

A A

7 5

A A

slide-48
SLIDE 48

Stability

7 5

A A

Lock

B

Unlock

B

slide-49
SLIDE 49

Stability

7 5

A A

Delete node

B B B

Add node

B B

slide-50
SLIDE 50

RGSep

More formally...

slide-51
SLIDE 51

Assertion syntax

Separation Logic Extended logic P, Q ::= false | emp | e = e′ | e → e′ | ∃x. P | P ⇒ Q | P ∗ Q | P − ⊛ Q h SL P − ⊛ Q ⇐ ⇒ h SL ¬(P − ∗ ¬Q) ⇐ ⇒ ∃h′. (h′ SL P) ∧ (h ⊎ h′ SL Q) p, q ::= P | P | p ∗ q | p ∧ q | p ∨ q | ∃x. p | ∀x. p local shared

slide-52
SLIDE 52

Assertion semantics

Split local state; share global state. l, s P ⇐ ⇒ l SL P l, s P ⇐ ⇒ l = ∅ ∧ (s SL P) l, s p1 ∗ p2 ⇐ ⇒ ∃l1, l2. (l = l1 ⊎ l2) ∧ (l1, s p1) ∧ (l2, s p2)

slide-53
SLIDE 53

Actions

x → tid, v, t

  • x → 0, v, t

x → 0, v, t

  • x → tid, v, t

x → tid, v, t

  • x → tid, v, y

∗ y → 0, v′, t x → tid, v, y ∗ y → tid, v′, t x → tid, v, t x → tid, v, y ∗ y → tid, v′, t x → tid, v, t ∗ y → tid, v′, t

slide-54
SLIDE 54

Judgements

(precondition, rely, guarantee, postcondition)

⊢ C sat (p, R, G, q)

slide-55
SLIDE 55

Parallel rule

Splits local state; Shares global state. ⊢ C1 sat (p1, R ∪ G2, G1, q1) ⊢ C2 sat (p2, R ∪ G1, G2, q2) ⊢ (C1C2) sat (p1 ∗ p2, R, G1 ∪ G2, q1 ∗ q2)

slide-56
SLIDE 56

Atomic commands

Shared state Local state P2, Q2 precise (P2 Q2) ∈ G ⊢ C sat (P1 ∗ P2, ∅, ∅, Q1 ∗ Q2) ⊢ (atomic C) sat

  • P1 ∗ P2 ∗ F , ∅, G, Q1 ∗ Q2 ∗ F
  • p, q stable under R

⊢ (atomic C) sat (p, ∅, G, q) ⊢ (atomic C) sat (p, R, G, q)

slide-57
SLIDE 57

Stability

iff S stable under P Q ((P − ⊛ S) ∗ Q) ⇒ S