Communicating State Transition Systems for Fine-Grained Concurrent - - PowerPoint PPT Presentation

communicating state transition systems for fine grained
SMART_READER_LITE
LIVE PREVIEW

Communicating State Transition Systems for Fine-Grained Concurrent - - PowerPoint PPT Presentation

Communicating State Transition Systems for Fine-Grained Concurrent Resources Aleksandar Nanevski Ruy Ley-Wild Ilya Sergey Germn Delbianco HOPE 2013 Reasoning about shared-memory concurrency How to model shared-memory


slide-1
SLIDE 1

Communicating State Transition Systems for Fine-Grained Concurrent Resources

Aleksandar Nanevski Ruy Ley-Wild Ilya Sergey Germán Delbianco

HOPE 2013

slide-2
SLIDE 2

Reasoning about shared-memory concurrency

slide-3
SLIDE 3

How to model shared-memory concurrency

slide-4
SLIDE 4

Two views at shared-memory concurrency

slide-5
SLIDE 5

Coarse-Grained Concurrency

Locks (or CCRs) are given as a primitive for synchronization.

slide-6
SLIDE 6

Fine-Grained Concurrency

Synchronization is implemented via atomic Read-Modify-Write commands.

slide-7
SLIDE 7

Two powerful tools for reasoning

slide-8
SLIDE 8

Concurrent Separation Logic Rely Guarantee Reasoning

O'Hearn [CONCUR'07], Brookes [CONCUR'04] Jones [TOPLAS'83]

slide-9
SLIDE 9

The essence of CSL

slide-10
SLIDE 10

The essence of CSL

  • The protocol for interference is fixed:

Conditional Critical Regions with Resource Invariants

slide-11
SLIDE 11

The essence of CSL

  • The protocol for interference is fixed:

Conditional Critical Regions with Resource Invariants

  • Interference doesn’t matter: CCR handle it
slide-12
SLIDE 12

Γ, r : I ` {p} c {q} Γ ` {p ⇤ I} resource r in c {q ⇤ I}

RESOURCECSL

slide-13
SLIDE 13

Γ, r : I ` {p} c {q} Γ ` {p ⇤ I} resource r in c {q ⇤ I}

RESOURCECSL

slide-14
SLIDE 14

“resource creation”

Γ, r : I ` {p} c {q} Γ ` {p ⇤ I} resource r in c {q ⇤ I}

RESOURCECSL

slide-15
SLIDE 15

Γ ` {p1} c1 {q1} Γ ` {p2} c2 {q2} Γ ` {p1 ⇤ p2} c1 k c2 {q1 ⇤ q2}

PARCSL

slide-16
SLIDE 16

Γ ` {p1} c1 {q1} Γ ` {p2} c2 {q2} Γ ` {p1 ⇤ p2} c1 k c2 {q1 ⇤ q2}

PARCSL

All interference is handled here

slide-17
SLIDE 17

The essence of R/G

slide-18
SLIDE 18

The essence of R/G

  • One can define arbitrary protocols

for process interference via Guarantee relation.

slide-19
SLIDE 19

The essence of R/G

  • One can define arbitrary protocols

for process interference via Guarantee relation.

  • Interference matters!

Atomic operations should be given specifications stable wrt Rely relation.

slide-20
SLIDE 20

R _ G2,G1 ` {p} c1 {q1} R _ G1,G2 ` {p} c2 {q2} R,G1 _ G2 ` {p} c1 k c2 {q1 ^ q2}

PARRG

“Forking/shuffling” parallel composition

} { _ G2 ` { R,G1

slide-21
SLIDE 21

R _ G2,G1 ` {p} c1 {q1} R _ G1,G2 ` {p} c2 {q2} R,G1 _ G2 ` {p} c1 k c2 {q1 ^ q2}

PARRG

“Forking/shuffling” parallel composition

} { _ G2 ` { R,G1

slide-22
SLIDE 22

R _ G2,G1 ` {p} c1 {q1} R _ G1,G2 ` {p} c2 {q2} R,G1 _ G2 ` {p} c1 k c2 {q1 ^ q2}

PARRG

“Forking/shuffling” parallel composition

} { _ G2 ` { R,G1

slide-23
SLIDE 23

Taking the best of two worlds

slide-24
SLIDE 24

Our Approach Resources Fine-Grained

slide-25
SLIDE 25

Resources Fine-Grained

slide-26
SLIDE 26

Resources

State Invariants

Fine-Grained

slide-27
SLIDE 27

Resources

State Invariants

Fine-Grained

Transitions

slide-28
SLIDE 28

Resources

State Invariants

Fine-Grained

Transitions

Composition

Forking/shuffling

slide-29
SLIDE 29

Resources

State Invariants

Fine-Grained

Transitions

Composition

Communication

Forking/shuffling

slide-30
SLIDE 30

Resources

State Invariants

Fine-Grained

Transitions

Composition

Communication

Forking/shuffling

Subjectivity

slide-31
SLIDE 31

Subjectivity

Communication

Systems

State Transition

slide-32
SLIDE 32

(Ley-Wild and Nanevski, POPL 2013)

Subjectivity

Communication

Systems

State Transition

slide-33
SLIDE 33

Subjective Communicating State-Transition Systems

slide-34
SLIDE 34

Concurroids

slide-35
SLIDE 35

Concurroid States

slide-36
SLIDE 36

| {z }

Self

Concurroid States

slide-37
SLIDE 37

| {z } | {z }

Self Other

Concurroid States

slide-38
SLIDE 38

| {z } |

{z } | {z }

Self Other Shared

Concurroid States

slide-39
SLIDE 39

| {z } |

{z } | {z }

Self Other Shared

  • Self - owned by me

Concurroid States

slide-40
SLIDE 40

| {z } |

{z } | {z }

Self Other Shared

  • Self - owned by me
  • Other - owned by all others

Concurroid States

slide-41
SLIDE 41

| {z } |

{z } | {z }

Self Other Shared

  • Self - owned by me
  • Other - owned by all others
  • Shared - owned by the resource

Concurroid States

slide-42
SLIDE 42

| {z } |

{z } | {z }

Self Other Shared

  • Self - owned by me
  • Other - owned by all others
  • Shared - owned by the resource
  • Self and Other are elements of

a Partial Commutative Monoid (PCM): (S, 0, ⊕).

Concurroid States

slide-43
SLIDE 43

Building a concurroid for Ticketed Lock

slide-44
SLIDE 44

n1

slide-45
SLIDE 45

n2 n1

slide-46
SLIDE 46

n2 n1 n1 ≤ n < n2

slide-47
SLIDE 47

n2 n1 n1 ≤ n < n2

  • wner
slide-48
SLIDE 48

n2 n1 n1 ≤ n < n2

  • wner

next

slide-49
SLIDE 49

lock = { x := DRAW; while (!TRY(x)) SKIP; } unlock = { INCR_OWN; } DRAW = { return FETCH_AND_INCREMENT(next); } TRY(n) = { return (n == owner); } INCR_OWN = { owner := owner + 1; }

Reference Implementation

slide-50
SLIDE 50

Ticketed Lock States

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-51
SLIDE 51

Ticketed Lock States

  • as, ao - auxiliaries controlled by self/other

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-52
SLIDE 52

Ticketed Lock States

  • as, ao - auxiliaries controlled by self/other
  • ts - tickets, owned by self

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-53
SLIDE 53

Ticketed Lock States

  • as, ao - auxiliaries controlled by self/other
  • ts - tickets, owned by self
  • to - tickets, owned by other threads

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-54
SLIDE 54

Ticketed Lock States

  • as, ao - auxiliaries controlled by self/other
  • ts - tickets, owned by self
  • to - tickets, owned by other threads
  • b - administrative flag to indicate locking

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-55
SLIDE 55

Ticketed Lock States

  • as, ao - auxiliaries controlled by self/other
  • ts - tickets, owned by self
  • to - tickets, owned by other threads
  • b - administrative flag to indicate locking
  • l - label to identify this particular instance of TLock concurroid

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-56
SLIDE 56

Ticketed Lock Invariant

slide-57
SLIDE 57

Ticketed Lock Invariant

s = ∧

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-58
SLIDE 58

Ticketed Lock Invariant

ts ⊕ to = {n | n1 ≤ n < n2} ∧ s = ∧

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

All dispensed tickets

slide-59
SLIDE 59

Ticketed Lock Invariant

ts ⊕ to = {n | n1 ≤ n < n2} ∧

   

   

s = ∧

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

All dispensed tickets

slide-60
SLIDE 60

Ticketed Lock Invariant

ts ⊕ to = {n | n1 ≤ n < n2} ∧

∨    

   

Locked

s = ∧

(n1 ∈ (ts ⊕ to) ∧ b = true ∧ h = emp)

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

All dispensed tickets

slide-61
SLIDE 61

Ticketed Lock Invariant

ts ⊕ to = {n | n1 ≤ n < n2} ∧

if n1 < n2 then n1 ∈ (ts ⊕ to) ∧ b = false ∧ I(as ⊕ ao)h else n1 = n2 ∧ b = false ∧ I(as ⊕ ao)h

   

   

Locked

s = ∧

(n1 ∈ (ts ⊕ to) ∧ b = true ∧ h = emp)

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

All dispensed tickets

slide-62
SLIDE 62

Ticketed Lock Invariant

ts ⊕ to = {n | n1 ≤ n < n2} ∧

if n1 < n2 then n1 ∈ (ts ⊕ to) ∧ b = false ∧ I(as ⊕ ao)h else n1 = n2 ∧ b = false ∧ I(as ⊕ ao)h

   

   

Locked Unlocked

s = ∧

(n1 ∈ (ts ⊕ to) ∧ b = true ∧ h = emp)

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

All dispensed tickets

slide-63
SLIDE 63

Ticketed Lock Invariant

ts ⊕ to = {n | n1 ≤ n < n2} ∧

if n1 < n2 then n1 ∈ (ts ⊕ to) ∧ b = false ∧ I(as ⊕ ao)h else n1 = n2 ∧ b = false ∧ I(as ⊕ ao)h

   

   

Locked Unlocked Transit

s = ∧

(n1 ∈ (ts ⊕ to) ∧ b = true ∧ h = emp)

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

All dispensed tickets

slide-64
SLIDE 64

Transitions

slide-65
SLIDE 65

Internal Transitions

slide-66
SLIDE 66

Internal Transitions

Intuition: drawing a ticket from the dispenser

slide-67
SLIDE 67

Internal Transitions

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

Intuition: drawing a ticket from the dispenser

slide-68
SLIDE 68

(ao, to) ` ⇣

hbi

  • wner 7! n1

h

∗ ∗

next 7! n2 + 1

(as, ts ∪ {n2})

Internal Transitions

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

Intuition: drawing a ticket from the dispenser

int

slide-69
SLIDE 69

(ao, to) ` ⇣

hbi

  • wner 7! n1

h

∗ ∗

next 7! n2 + 1

(as, ts ∪ {n2})

Internal Transitions

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

Intuition: drawing a ticket from the dispenser

int

slide-70
SLIDE 70

(ao, to) ` ⇣

hbi

  • wner 7! n1

h

∗ ∗

next 7! n2 + 1

(as, ts ∪ {n2})

Internal Transitions

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

Intuition: drawing a ticket from the dispenser

int

slide-71
SLIDE 71

Communication

slide-72
SLIDE 72

Intuition:

Channels with different polarity

slide-73
SLIDE 73

Intuition:

Channels with different polarity

Implementation:

Acquire/Release transitions

(communication is via heap ownership transfer)

slide-74
SLIDE 74

Acquire Transitions

Intuition: the lock obtains back ownership over the heap and increments the service counter (owner)

slide-75
SLIDE 75

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

emp

htruei

(as, ts ∪ {n1})

(ao, to)

∗ ∗

` ⇣

h

hfalsei

next 7! n2

(as, ts)

  • wner 7! n1 + 1

Acquire Transitions

Intuition: the lock obtains back ownership over the heap and increments the service counter (owner)

acqh

1

slide-76
SLIDE 76

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

emp

htruei

(as, ts ∪ {n1})

(ao, to)

∗ ∗

` ⇣

h

hfalsei

next 7! n2

(as, ts)

  • wner 7! n1 + 1

Acquire Transitions

Intuition: the lock obtains back ownership over the heap and increments the service counter (owner)

acqh

1

slide-77
SLIDE 77

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

emp

htruei

(as, ts ∪ {n1})

(ao, to)

∗ ∗

` ⇣

h

hfalsei

next 7! n2

(as, ts)

  • wner 7! n1 + 1

Acquire Transitions

Intuition: the lock obtains back ownership over the heap and increments the service counter (owner)

acqh

1

slide-78
SLIDE 78

Release Transitions

Intuition: the lock gave up ownership over the heap

slide-79
SLIDE 79

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

emp

htruei

(as, ts ∪ {n1})

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

hfalsei

Release Transitions

Intuition: the lock gave up ownership over the heap

relh

1

slide-80
SLIDE 80

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

emp

htruei

(as, ts ∪ {n1})

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

hfalsei

Release Transitions

Intuition: the lock gave up ownership over the heap

relh

1

slide-81
SLIDE 81

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

emp

htruei

(as, ts ∪ {n1})

(ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

hfalsei

Release Transitions

Intuition: the lock gave up ownership over the heap

relh

1

slide-82
SLIDE 82

Transitions don’t change the other part!

slide-83
SLIDE 83

Transitions don’t change the other part! Transitions = Guarantee

slide-84
SLIDE 84

Transposing the Concurroid

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-85
SLIDE 85

Transposing the Concurroid

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

slide-86
SLIDE 86

Transposing the Concurroid

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

Transitions of transposed = Rely

slide-87
SLIDE 87

Transposing the Concurroid

(as, ts) (ao, to)

  • wner 7! n1

next 7! n2 ∗ ∗

` ⇣

h

hbi

Transitions of transposed = Rely

reminiscent to tokens by Turon et al. [POPL’13, ICFP’13]

slide-88
SLIDE 88

Composing Concurroids

slide-89
SLIDE 89

Intuition: Connect communication channels with right polarity

slide-90
SLIDE 90

` ⇣

p ⇣

Intuition: Connect communication channels with right polarity

slide-91
SLIDE 91

` ⇣

p ⇣

Intuition: Connect communication channels with right polarity

acq acq acq acq rel rel rel rel

  • Some channels might be left loose
  • Same channels might be connected several times
  • Some channels might be shut down
slide-92
SLIDE 92

Entanglement Operators

⋈, ⋊, ⋉,×...

Connect two concurroids by connecting some of their acquire/release transitions.

slide-93
SLIDE 93

Entanglement Operators

⋈, ⋊, ⋉,×...

Connect two concurroids by connecting some of their acquire/release transitions. Connected A/R transitions become internal for the entanglement.

slide-94
SLIDE 94
  • “apart”, doesn’t connect channels,

leaves all loose.

×

Useful Entanglement Operators

  • connects all channels pair-wise,

shuts channels of the right operand, leaves left one’s loose

slide-95
SLIDE 95
  • “apart”, doesn’t connect channels,

leaves all loose.

×

Useful Entanglement Operators

  • connects all channels pair-wise,

shuts channels of the right operand, leaves left one’s loose

Lemma: U ⋊ (V1 × V2) = (U ⋊ V1) ⋊ V2

slide-96
SLIDE 96

Programming with Concurroids

slide-97
SLIDE 97

Transitions are not yet commands!

slide-98
SLIDE 98

Transitions are not yet commands!

They only describe some correct behavior.

slide-99
SLIDE 99

Atomic Actions

  • Defined as subsets of internal transitions
  • Specify the result
  • Operational meaning:

READ, WRITE, SKIP and various RMW-commands

  • Synchronize ownership transfer and

manipulation with auxiliaries

slide-100
SLIDE 100

Recap: TLock Implementation

lock = { x := DRAW; while (!TRY(x)) SKIP; } unlock = { INCR_OWN; }

slide-101
SLIDE 101

Recap: TLock Implementation

lock = { x := DRAW; while (!TRY(x)) SKIP; } unlock = { INCR_OWN; }

slide-102
SLIDE 102

TRY(n1) Action Specification

slide-103
SLIDE 103

TRY(n1) Action Specification

TRY(n1)(s, s0, res) ,

slide-104
SLIDE 104

s =

         

         

TRY(n1) Action Specification

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

if then else

(n1 = n0

1)

s0 = s s0 = p ⇣

ho

hs ⊕ h

(ao, to)

next 7! n2 ∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

∧ I(as ⊕ ao)h

       

TRY(n1)(s, s0, res) ,

∧ res = true ∧ res = false

slide-105
SLIDE 105

s =

         

         

TRY(n1) Action Specification

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

if then else

(n1 = n0

1)

s0 = s s0 = p ⇣

ho

hs ⊕ h

(ao, to)

next 7! n2 ∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

∧ I(as ⊕ ao)h

       

TRY(n1)(s, s0, res) ,

∧ res = true ∧ res = false

slide-106
SLIDE 106

s =

         

         

TRY(n1) Action Specification

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

if then else

(n1 = n0

1)

s0 = s s0 = p ⇣

ho

hs ⊕ h

(ao, to)

next 7! n2 ∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

∧ I(as ⊕ ao)h

       

TRY(n1)(s, s0, res) ,

∧ res = true ∧ res = false

slide-107
SLIDE 107

s =

         

         

TRY(n1) Action Specification

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

if then else

(n1 = n0

1)

s0 = s s0 = p ⇣

ho

hs ⊕ h

(ao, to)

next 7! n2 ∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

∧ I(as ⊕ ao)h

       

TRY(n1)(s, s0, res) ,

∧ res = true ∧ res = false

slide-108
SLIDE 108

What about modular reasoning?

slide-109
SLIDE 109

x := DRAW;

slide-110
SLIDE 110

x := DRAW;

      

             

      

` ⇣ (as, ts)

... ...

x = n1 ∧

` ⇣ (as, ts ∪ {n1})

... ...

slide-111
SLIDE 111

x := DRAW;

      

      

             

` ⇣ (as, ts)

... ...

x = n1 ∧

` ⇣ (as, ts ∪ {n1})

... ...

slide-112
SLIDE 112

lock = { while (!TRY(x)) SKIP; }

x := DRAW;

      

      

             

` ⇣ (as, ts)

... ...

x = n1 ∧

` ⇣ (as, ts ∪ {n1})

... ...

slide-113
SLIDE 113

lock = { while (!TRY(x)) SKIP; }

x := DRAW;

      

      

             

| {z }

Defined in

` ⇣

p ⇣

` ⇣ (as, ts)

... ...

x = n1 ∧

` ⇣ (as, ts ∪ {n1})

... ...

slide-114
SLIDE 114

Context Weakening!

slide-115
SLIDE 115

Injection Rule

{p}C {q} @ U r stable under V {p ⇤ r} injectV C {q ⇤ r} @ U o V

INJECT

where ⧓ = ⋈, ⋊, ⋉,×...

slide-116
SLIDE 116

Injection Rule

{p}C {q} @ U r stable under V {p ⇤ r} injectV C {q ⇤ r} @ U o V

INJECT

where ⧓ = ⋈, ⋊, ⋉,×...

slide-117
SLIDE 117

lock = { while (!TRY(x)) SKIP; }

` ⇣ (as, ts)

... ...

` ⇣ (as, ts ∪ {n1})

... ...

x :=

      

      

      

       DRAW ;

x = n1 ∧

slide-118
SLIDE 118

lock = { while (!TRY(x)) SKIP; }

` ⇣ (as, ts)

... ...

` ⇣ (as, ts ∪ {n1})

... ...

x :=

      

      

      

       DRAW ;

injectp(

)

x = n1 ∧

slide-119
SLIDE 119

lock = { while (!TRY(x)) SKIP; }

` ⇣ (as, ts)

... ...

` ⇣ (as, ts ∪ {n1})

... ...

x :=

      

      

      

      

⊕ ⊕

DRAW ;

injectp(

)

x = n1 ∧

p ⇣ hs

... ...

p ⇣ hs

... ...

slide-120
SLIDE 120

lock = { while (!TRY(x)) SKIP; }

` ⇣ (as, ts)

... ...

` ⇣ (as, ts ∪ {n1})

... ...

x :=

      

      

      

      

⊕ ⊕

r r

DRAW ;

injectp(

)

x = n1 ∧

p ⇣ hs

... ...

p ⇣ hs

... ...

slide-121
SLIDE 121

Creating and disposing concurroids

slide-122
SLIDE 122

Creating and disposing resources

slide-123
SLIDE 123

CSL Resource Rule

Γ, r : I ` {p} c {q} Γ ` {p ⇤ I} resource r in c {q ⇤ I}

RESOURCECSL

slide-124
SLIDE 124

CSL Resource Rule

Γ, r : I ` {p} c {q} Γ ` {p ⇤ I} resource r in c {q ⇤ I}

RESOURCECSL

slide-125
SLIDE 125

CSL Resource Rule

Γ, r : I ` {p} c {q} Γ ` {p ⇤ I} resource r in c {q ⇤ I}

RESOURCECSL

slide-126
SLIDE 126

Allocating a Ticketed Lock

(owner, next ) = { }

  • wner := 0;

next := 0; with_tlock , body

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

slide-127
SLIDE 127

Allocating a Ticketed Lock

(owner, next ) = { }

  • wner := 0;

next := 0; with_tlock , body

Scoped concurroid creation/disposal hidecoh(tlock `(owner,next)),(as,∅) {

} body;

slide-128
SLIDE 128

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

slide-129
SLIDE 129

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

      

      

slide-130
SLIDE 130

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec

      

      

slide-131
SLIDE 131

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec Initial “self” auxiliaries

      

      

slide-132
SLIDE 132

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec Initial “self” auxiliaries

      

      

      

      

` ⇣

hfalsei

(as, ts) (1, ∅)

p ⇣

slide-133
SLIDE 133

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec Initial “self” auxiliaries

      

      

      

      

` ⇣

hfalsei

(as, ts) (1, ∅)

p ⇣

slide-134
SLIDE 134

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec Initial “self” auxiliaries

      

      

      

      

` ⇣

hfalsei

(as, ts) (1, ∅)

p ⇣

  • wner 7! 0

h

next 7! 0

hs ho

∗ ∗

slide-135
SLIDE 135

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec Initial “self” auxiliaries

      

      

      

      

` ⇣

hfalsei

(as, ts) (1, ∅)

∗ ∗

  • wner 7! 0

h

next 7! 0

p ⇣ hs

ho

slide-136
SLIDE 136

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec Initial “self” auxiliaries

p ⇣ h0

  • h0

s

      

      

      

      

      

      

next 7! n2

` ⇣

hbi

  • wner 7! n1

h0

(1, ∅)

∗ ∗

(a0

s, t0 s)

` ⇣

hfalsei

(as, ts) (1, ∅)

∗ ∗

  • wner 7! 0

h

next 7! 0

p ⇣ hs

ho

slide-137
SLIDE 137

hidecoh(tlock `(owner,next)),(as,∅) {

} body;

p ⇣ ho

hs

h

∗ ∗ ∗

  • wner 7! 0

next 7! 0

Concurroid spec Initial “self” auxiliaries

p ⇣ h0

  • h0

s

      

      

      

      

      

      

      

      

next 7! n2

` ⇣

hbi

  • wner 7! n1

h0

(1, ∅)

∗ ∗

(a0

s, t0 s)

p ⇣

∗ ∗ ∗

next 7! n2

h0

h0

s

  • wner 7! n1

h0

  • ` ⇣

hfalsei

(as, ts) (1, ∅)

∗ ∗

  • wner 7! 0

h

next 7! 0

p ⇣ hs

ho

slide-138
SLIDE 138

Only One Basic Concurroid

p ⇣ hs ho

slide-139
SLIDE 139

Parallel Composition

{p1}C1 {q1} @ U {p2}C2 {q2} @ U {p1 ~ p2}C1 k C2 {q1 ~ q2} @ U

PAR

slide-140
SLIDE 140

Parallel Composition

{p1}C1 {q1} @ U {p2}C2 {q2} @ U {p1 ~ p2}C1 k C2 {q1 ~ q2} @ U

PAR

“Fork-shuffling” is handled by subjectivity: R/G are encoded by U.

slide-141
SLIDE 141

Not discussed today

  • A concurroid for CAS-based lock
  • A concurroid model for readers/writers
  • Allocation
  • Non-scoped locks
  • Soundness theorem and its proof
  • Abstract predicates (yes, we can do it, too)
slide-142
SLIDE 142

Implementation

  • Implementation in Coq (metatheory, logic, proofs):

shallow embedding into the CIC

  • Higher-orderness and abstraction for free
  • Reasoning in HTT
  • style:

specifications are monadic types

  • Some automation is done for splitting the state

among concurroids

  • CAS-lock and Ticketed lock are fully implemented
slide-143
SLIDE 143

To take away

slide-144
SLIDE 144

To take away

Goal 1: Model fine-grained concurrent resources with arbitrary protocols

slide-145
SLIDE 145

To take away

Goal 1: Model fine-grained concurrent resources with arbitrary protocols Goal 2: Combine simplicity and modularity of Concurrent Separation Logic with the power of Rely-Guarantee reasoning

slide-146
SLIDE 146

To take away

Concurroids

Goal 1: Model fine-grained concurrent resources with arbitrary protocols Goal 2: Combine simplicity and modularity of Concurrent Separation Logic with the power of Rely-Guarantee reasoning Proposal:

“fine-grained resources”

slide-147
SLIDE 147

To take away

Concurroids

Goal 1: Model fine-grained concurrent resources with arbitrary protocols Goal 2: Combine simplicity and modularity of Concurrent Separation Logic with the power of Rely-Guarantee reasoning

  • State Transition Systems
  • Communication
  • Subjectivity

      

Proposal:

“fine-grained resources”

slide-148
SLIDE 148

To take away

Concurroids

Goal 1: Model fine-grained concurrent resources with arbitrary protocols Goal 2: Combine simplicity and modularity of Concurrent Separation Logic with the power of Rely-Guarantee reasoning

  • State Transition Systems
  • Communication
  • Subjectivity

      

Thanks! Proposal:

“fine-grained resources”

slide-149
SLIDE 149

Backup Slides

slide-150
SLIDE 150

CSL + FG protocols

  • CSL + Permissions

Bornat et al. [POPL'05]

  • Auxiliaries for FG

Parkinson et al. [POPL'07]

  • Storable locks

Gotsman et al. [APLAS'07]

  • Concurrent Abstract Predicates (CAP)

Dindsdale-Young et al. [ECOOP'10]

  • Higher-Order CAP

Svendsen et al. [ESOP'13]

  • Impredicative CAP

Svendsen and Birkedal [HOPE'13]

  • ...

RG + Resource composition

  • Separate Assume-Guarantee (SAGL)

Feng et al. [ESOP'07]

  • RGSep

Vafeiadis and Parkinson [CONCUR'07]

  • Local RG

Feng [POPL'09]

  • Deny-Guarantee

Dods et al. [ESOP'09]

  • ...

Taking the best of two worlds

slide-151
SLIDE 151
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦

slide-152
SLIDE 152
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n }

slide-153
SLIDE 153
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n } +

slide-154
SLIDE 154
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n } + { as ↦ 0, ao ↦ n + 0 }

slide-155
SLIDE 155
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n } + { as ↦ 0, ao ↦ n + 0 } { as ↦ 0, ao ↦ n + 0 }

slide-156
SLIDE 156
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n } + { as ↦ 0, ao ↦ n + 0 } { as ↦ 0, ao ↦ n + 0 } { as ↦ 1, ao ↦ n1 }

slide-157
SLIDE 157
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n } + { as ↦ 0, ao ↦ n + 0 } { as ↦ 0, ao ↦ n + 0 } { as ↦ 1, ao ↦ n1 } { as ↦ 1, ao ↦ n2 }

slide-158
SLIDE 158
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n } + { as ↦ 0, ao ↦ n + 0 } { as ↦ 0, ao ↦ n + 0 } { as ↦ 1, ao ↦ n1 } { as ↦ 1, ao ↦ n2 } { as ↦ 1 + 1, ∃n’, ao ↦ n’, n1 = n + 1, n2 = n’ + 1 }

slide-159
SLIDE 159
  • lock;

unlock;

x := x + 1;

as := as + 1; lock; unlock;

x := x + 1;

as := as + 1; (as ⊕ ao) RI(lock) ≝ x ↦ { as ↦ , ao ↦ n } + { as ↦ 0, ao ↦ n + 0 } { as ↦ 0, ao ↦ n + 0 } { as ↦ 1, ao ↦ n1 } { as ↦ 1, ao ↦ n2 } { as ↦ 2, ao ↦ - }

slide-160
SLIDE 160

Verifying Programs with Atomic Actions

slide-161
SLIDE 161

Taming Stability

slide-162
SLIDE 162

s =

         

         

TRY(n) Action Specification

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

if then else

(n1 = n0

1)

s0 = s s0 = p ⇣

ho

hs ⊕ h

(ao, to)

next 7! n2 ∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

∧ I(as ⊕ ao)h

       

∧ res = true ∧ res = false

TRY(n1)(s, s0, res) ,

slide-163
SLIDE 163

s =

         

         

TRY(n) Action Specification

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

if then else

(n1 = n0

1)

s0 = s s0 = p ⇣

ho

hs ⊕ h

(ao, to)

next 7! n2 ∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

∧ I(as ⊕ ao)h

       

Not stable!

∧ res = true ∧ res = false

TRY(n1)(s, s0, res) ,

slide-164
SLIDE 164

Stable Hoare-style Rule for TRY(n)

TRY(n1)

slide-165
SLIDE 165

Stable Hoare-style Rule for TRY(n)

s =

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

             

TRY(n1)

slide-166
SLIDE 166

Stable Hoare-style Rule for TRY(n)

s =

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

             

if then else (n1 = n0

1)

s0 =

I(as ⊕ ao)h

∃h0

  • , n0

2, t0

  • ,

∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

next 7! n0

2

(ao, t0

  • )

p ⇣ hs ⊕ h h0

      

TRY(n1)

∃h0

  • , n0

1, n0 2, t0

  • , b0, h0, a0
  • , t0
  • ,

p ⇣ h0

  • hs

s0 =

∧ res = true ∧ coh(s0) ⊕

∗ ∗

` ⇣ (as, ts ∪ {n1})

  • wner 7! n0

1

hb0i h0

next 7! n0

2

(a0

  • , t0
  • )

∧coh(s0)

   

   

             

slide-167
SLIDE 167

Stable Hoare-style Rule for TRY(n)

s =

(ao, to)

next 7! n2 ∗ ∗

` ⇣

h

(as, ts ∪ {n1})

  • wner 7! n0

1

hbi

p ⇣ hs ho

             

if then else (n1 = n0

1)

s0 =

I(as ⊕ ao)h

∃h0

  • , n0

2, t0

  • ,

∗ ∗

` ⇣

emp

(as, ts ∪ {n1})

htruei

  • wner 7! n1

next 7! n0

2

(ao, t0

  • )

p ⇣ hs ⊕ h h0

      

TRY(n1)

∃h0

  • , n0

1, n0 2, t0

  • , b0, h0, a0
  • , t0
  • ,

p ⇣ h0

  • hs

s0 =

∧ res = true ∧ coh(s0) ⊕

∗ ∗

` ⇣ (as, ts ∪ {n1})

  • wner 7! n0

1

hb0i h0

next 7! n0

2

(a0

  • , t0
  • )

∧coh(s0)

   

   

             

slide-168
SLIDE 168
  • Subjective state allows one to give

a lower bound to the joint contribution: “I know what is my contribution.”

  • Hiding (or scoping) allows one to provide

an upper bound for the contribution:

“When everyone is done, we can the auxiliaries are summed up. ”

On the role of hiding

slide-169
SLIDE 169

Some General Coherence Properties

  • Heap-consistency:

hself ⊕ hother ⊕ hshared is defined

  • Self-other consistency:

(as, ts) ⊕ (ao, to) is defined

  • Fork-join consistency:

... gs ⊕ g go ... gs go ⊕ g

⟺ coh

coh

◆ ◆ ✓ ✓

slide-170
SLIDE 170

...

◆ int ✓

,

...

g0

s

gs

go ⊕ g go ⊕ g

Internal Transition Properties

  • Coherence-consistency: int(s1, s2) ⇒ coh(s1) ∧ coh(s2)
  • Reflexivity
  • Heap footprint preservation:

int(s1, s2) ⇒ dom(heap(s1)) = dom(heap(s2))

  • Self-locality: int(s1, s2) ⇒ other(s1) = other(s2)
  • Fork-join consistency:

...

◆ int ✓

,

...

go go

gs ⊕ g

g0

s ⊕ g

slide-171
SLIDE 171

Acquire/Release Properties

  • Coherence-consistency:

acq(s1, s2) ⇒ coh(s1) ∧ coh(s2)

  • Self-locality:

acq(s1, s2) ⇒ other(s1) = other(s2)

  • Fork-join consistency
slide-172
SLIDE 172

rl ⇣ wl ⇣

lkw 7! bw lkr 7! br ∗

count 7! n∗

(mw

s , as)

(mw

  • , ao)

(mr

  • , No)

(mr

s, Ns)

Readers-Writers

h

count 7! n

h hw hr

Ir(Ns ⊕ No, hr) , (Ns ⊕ No = n) ∧ (Ns ⊕ No = 0 = ⇒ hr = emp)

Iw(as ⊕ ao, hw) , . . .

slide-173
SLIDE 173

rl ⇣ wl ⇣

lkw 7! bw lkr 7! br ∗

count 7! n∗

(mw

s , as)

(mw

  • , ao)

(mr

  • , No)

(mr

s, Ns)

Readers-Writers

h

count 7! n

h hw hr

Ir(Ns ⊕ No, hr) , (Ns ⊕ No = n) ∧ (Ns ⊕ No = 0 = ⇒ hr = emp)

Iw(as ⊕ ao, hw) , . . .