Modeling and Analyzing Concurrent Systems Robert B. France - - PowerPoint PPT Presentation

modeling and analyzing concurrent systems
SMART_READER_LITE
LIVE PREVIEW

Modeling and Analyzing Concurrent Systems Robert B. France - - PowerPoint PPT Presentation

Modeling and Analyzing Concurrent Systems Robert B. France 1 Overview Why model and analyze concurrent systems? How are concurrent systems modeled?


slide-1
SLIDE 1

Modeling ¡and ¡Analyzing ¡ Concurrent ¡Systems ¡

Robert ¡B. ¡France ¡

1

slide-2
SLIDE 2

Overview ¡

  • Why ¡model ¡and ¡analyze ¡concurrent ¡systems? ¡
  • How ¡are ¡concurrent ¡systems ¡modeled? ¡
  • How ¡are ¡concurrent ¡systems ¡analyzed? ¡

2

slide-3
SLIDE 3

References ¡

Principles ¡of ¡Model ¡Checking ¡

Christel ¡Baier ¡and ¡Joost-­‑Pieter ¡Katoen, ¡MIT ¡ Press ¡ Some ¡of ¡the ¡slides ¡use ¡diagrams ¡and ¡text ¡ extracted ¡from ¡the ¡above ¡book ¡

3

slide-4
SLIDE 4

Overview ¡

  • Why ¡model ¡and ¡analyze ¡concurrent ¡systems? ¡
  • How ¡are ¡concurrent ¡systems ¡modeled? ¡
  • How ¡are ¡concurrent ¡systems ¡analyzed? ¡

4

slide-5
SLIDE 5

Why ¡model ¡concurrent ¡systems? ¡

  • Distributed, ¡concurrent ¡systems ¡are ¡becoming ¡

commonplace, ¡but ¡they ¡are ¡notoriously ¡difficult ¡to ¡ develop ¡

– network ¡applicaOons, ¡data ¡communicaOon ¡protocols, ¡mulOthreaded ¡code, ¡ client-­‑server ¡applicaOons ¡

  • Concurrency-­‑specific ¡errors: ¡deadlock, ¡livelock ¡

– A ¡deadlock ¡occurs ¡when ¡the ¡system ¡cannot ¡has ¡reached ¡a ¡ state ¡in ¡which ¡no ¡work ¡is ¡done ¡but ¡at ¡least ¡one ¡process ¡in ¡the ¡ system ¡needs ¡to ¡complete ¡its ¡tasks ¡ – A ¡livelock ¡occurs ¡when ¡the ¡processes ¡in ¡a ¡system ¡are ¡stuck ¡in ¡ a ¡repeOOve ¡task ¡and ¡make ¡no ¡progress ¡towards ¡their ¡ funcOonal ¡goals. ¡

  • These ¡types ¡of ¡behavioral ¡errors ¡can ¡be ¡mechanically ¡

detected ¡if ¡the ¡systems ¡are ¡properly ¡modeled ¡and ¡ analyzed ¡

5

slide-6
SLIDE 6

Common ¡flaws ¡in ¡concurrent ¡systems ¡

  • UnderspecificaOon: ¡Model ¡is ¡incomplete, ¡imprecise ¡or ¡allows ¡behavior ¡

that ¡should ¡not ¡be ¡allowed ¡(i.e., ¡model ¡is ¡too ¡permissive). ¡

  • OverspecificaOon: ¡Model ¡disallows ¡behavior ¡that ¡should ¡be ¡allowed, ¡that ¡

is, ¡model ¡is ¡to ¡restricOve ¡

  • ViolaOons ¡of ¡safety ¡properOes: ¡A ¡safety ¡property ¡is ¡a ¡property ¡that ¡must ¡

not ¡be ¡violated ¡ ¡

– “nothing ¡bad ¡should ¡happen”; ¡a ¡bad ¡behavior ¡should ¡never ¡occurs ¡ – An ¡invariant ¡is ¡an ¡example ¡of ¡a ¡safety ¡property ¡ – Example ¡1: ¡Mutual ¡exclusion ¡property ¡– ¡at ¡most ¡one ¡process ¡is ¡in ¡its ¡criOcal ¡secOon ¡ at ¡any ¡given ¡Ome ¡ – Example ¡2: ¡Absence ¡of ¡deadlocks: ¡

  • ViolaOons ¡of ¡liveness ¡properOes: ¡Set ¡of ¡properOes ¡that ¡a ¡system ¡must ¡

saOsfy, ¡i.e., ¡properOes ¡that ¡require ¡desired ¡events ¡eventually ¡occur ¡

– “something ¡good ¡eventually ¡happens” ¡ – Example ¡1: ¡StarvaOon ¡freedom ¡(e.g., ¡each ¡process ¡waiOng ¡to ¡enter ¡its ¡criOcal ¡ secOon ¡will ¡eventually ¡enter ¡its ¡criOcal ¡secOon. ¡ – Example ¡2: ¡Progress: ¡A ¡process ¡will ¡eventually ¡perform ¡a ¡non-­‑skip ¡step ¡

6

slide-7
SLIDE 7

What ¡is ¡Model ¡Checking? ¡

  • “Model ¡checking ¡is ¡an ¡automated ¡technique ¡that, ¡

given ¡a ¡finite-­‑state ¡model ¡of ¡a ¡system ¡and ¡a ¡ logical ¡property, ¡systemaOcally ¡checks ¡whether ¡ this ¡property ¡holds ¡for ¡(a ¡given ¡iniOal ¡state ¡in) ¡ that ¡model.” ¡[Clarke ¡& ¡Emerson ¡1981]: ¡

  • Model ¡checking ¡tools ¡automaOcally ¡verify ¡

whether ¡M∣=φ, ¡holds, ¡where ¡M ¡is ¡a ¡(finite-­‑state) ¡ model ¡of ¡a ¡system ¡and ¡property ¡φ ¡(phi) ¡ characterizes ¡a ¡set ¡of ¡allowed ¡behaviors. ¡

– M ¡has ¡behavior ¡that ¡is ¡allowed ¡by ¡φ ¡ – Check ¡that ¡M ¡is ¡a ¡model ¡of ¡φ ¡

7

slide-8
SLIDE 8

Model ¡Checking ¡process ¡

  • 1. Construct ¡a ¡model ¡of ¡the ¡system ¡(M) ¡
  • 2. Formalize ¡the ¡properOes ¡that ¡will ¡be ¡evaluated ¡

in ¡the ¡model ¡(P) ¡

  • 3. Use ¡a ¡model ¡checker ¡to ¡determine ¡if ¡M ¡saOsfies ¡
  • P. ¡Three ¡results ¡are ¡possible: ¡
  • 1. The ¡model ¡M ¡saOsfies ¡the ¡property ¡P, ¡i.e. ¡M ¡|= ¡P ¡
  • 2. M ¡does ¡not ¡saOsfy ¡P; ¡in ¡this ¡case ¡a ¡counterexample ¡is ¡

produced ¡

  • 3. No ¡conclusive ¡result ¡is ¡produced ¡by ¡the ¡model ¡

checker ¡(model ¡checker ¡ran ¡out ¡of ¡space ¡or ¡Ome) ¡ ¡

8

slide-9
SLIDE 9

What ¡is ¡meant ¡by ¡“model” ¡in ¡“model ¡ checker”? ¡

  • The ¡term ¡“model” ¡as ¡used ¡in ¡“model ¡checker” ¡is ¡an ¡

assignment ¡of ¡values ¡to ¡variables ¡in ¡a ¡logical ¡formula ¡ that ¡makes ¡the ¡formula ¡true. ¡AlternaOvely, ¡a ¡formula ¡ defines ¡a ¡family ¡of ¡“models” ¡or ¡instances ¡(where ¡an ¡ instance ¡saOsfies ¡the ¡formula) ¡

– For ¡example, ¡a ¡model ¡of ¡a ¡proposiOon ¡is ¡an ¡assignment ¡of ¡ truth ¡values ¡to ¡the ¡proposiOon ¡variables ¡that ¡makes ¡the ¡ proposiOon ¡true ¡(e.g., ¡a ¡line ¡in ¡a ¡truth ¡table ¡is ¡a ¡model) ¡

  • A ¡model ¡checker ¡checks ¡whether ¡a ¡system ¡model, ¡M, ¡is ¡

an ¡instance ¡of ¡the ¡property, ¡φ ¡

– That ¡is, ¡it ¡checks ¡if ¡the ¡system ¡model ¡is ¡an ¡assignment ¡of ¡ values ¡to ¡variables ¡in ¡the ¡property ¡that ¡makes ¡the ¡property ¡

  • true. ¡ ¡ ¡ ¡

9

slide-10
SLIDE 10

Is ¡the ¡Alloy ¡Analyzer ¡a ¡Model ¡Checker? ¡

  • No! ¡It ¡is ¡a ¡Model ¡Finder ¡
  • The ¡Analyzer ¡generates ¡an ¡instance ¡that ¡

saOsfies ¡the ¡constraints ¡in ¡signatures, ¡ facts ¡and ¡the ¡condiOon ¡in ¡the ¡predicates ¡

  • r ¡asserOons. ¡

10

slide-11
SLIDE 11

Overview ¡

  • Why ¡model ¡and ¡analyze ¡concurrent ¡systems? ¡
  • How ¡are ¡concurrent ¡systems ¡modeled? ¡
  • How ¡are ¡concurrent ¡systems ¡analyzed? ¡

11

slide-12
SLIDE 12

How ¡can ¡we ¡describe ¡a ¡system ¡so ¡that ¡it ¡ can ¡be ¡mechanically ¡model-­‑checked? ¡

  • First ¡we ¡focus ¡on ¡linear ¡temporal ¡behavioral ¡properOes ¡

– Linear ¡model ¡of ¡Ome; ¡no ¡branching ¡in ¡the ¡Omeline ¡over ¡ which ¡behaviors ¡are ¡observed ¡

  • Behaviors ¡expressed ¡in ¡terms ¡of ¡TransiOon ¡Systems ¡

that ¡describe ¡the ¡effect ¡of ¡operaOons ¡on ¡the ¡system’s ¡

  • state. ¡
  • A ¡linear ¡temporal ¡(LT) ¡property ¡characterizes ¡a ¡set ¡of ¡

state ¡transiOons ¡

  • A ¡model ¡saOsfies ¡a ¡linear ¡temporal ¡property ¡if ¡the ¡state ¡

transiOons ¡it ¡defines ¡are ¡all ¡included ¡in ¡the ¡transiOons ¡ characterized ¡by ¡the ¡LT ¡property. ¡

12

slide-13
SLIDE 13

TransiOon ¡systems ¡

13

slide-14
SLIDE 14

Using ¡TransiOon ¡Systems ¡to ¡model ¡ system ¡behavior ¡

  • A ¡Transi7on ¡System ¡(TS) ¡is ¡a ¡directed ¡graph ¡

where ¡nodes ¡represent ¡states ¡and ¡edges ¡ represent ¡transiOons ¡between ¡states ¡

  • A ¡state ¡describes ¡informaOon ¡about ¡a ¡system ¡at ¡a ¡

parOcular ¡point ¡in ¡Ome ¡(cf. ¡state ¡in ¡Alloy) ¡

– E.g., ¡the ¡state ¡of ¡a ¡traffic ¡light ¡indicates ¡the ¡color ¡of ¡ the ¡light ¡that ¡is ¡illuminated ¡at ¡a ¡point ¡in ¡Ome ¡

  • A ¡transi7on ¡describes ¡the ¡condiOons ¡under ¡which ¡

a ¡system ¡moves ¡from ¡one ¡state ¡to ¡another. ¡

14

slide-15
SLIDE 15

A ¡(toy) ¡example ¡of ¡a ¡simple ¡TS ¡

15

Transitions are associated with action labels that indicate the actions that cause the transition.

  • insert_coin is a user action
  • get_soda, get_beer are actions performed by the machine
  • τ denotes an activity that is not of interest to the modeler (e.g.,

it represents an internal activity of the vending machine)

slide-16
SLIDE 16

Transi7on ¡System ¡(TS): ¡Formal ¡Defini7on ¡

A ¡transi7on ¡system ¡TS ¡is ¡a ¡tuple ¡(S, ¡Act,→, ¡I,AP, ¡L) ¡where ¡

– ¡S ¡is ¡a ¡set ¡of ¡states, ¡ – Act ¡is ¡a ¡set ¡of ¡acOons, ¡ – -­‑> ¡⊆ ¡S ¡× ¡Act ¡× ¡S ¡is ¡a ¡transiOon ¡relaOon ¡(the ¡first ¡element ¡in ¡the ¡triplet ¡is ¡the ¡source ¡state, ¡ the ¡second ¡element ¡is ¡an ¡acOon ¡and ¡the ¡third ¡element ¡is ¡the ¡target ¡state ¡of ¡the ¡transiOon) ¡ – I ¡⊆ ¡S ¡is ¡a ¡set ¡of ¡iniOal ¡states, ¡ – AP ¡is ¡a ¡set ¡of ¡atomic ¡proposiOons, ¡and ¡ – ¡L ¡: ¡S ¡→2AP ¡ ¡ ¡is ¡a ¡labeling ¡funcOon ¡(2AP ¡ ¡is ¡the ¡power ¡set ¡of ¡AP) ¡

TS ¡is ¡called ¡finite ¡if ¡S, ¡Act, ¡and ¡AP ¡are ¡finite. ¡ (s, ¡act, ¡s’) ¡in ¡-­‑> ¡is ¡wrimen ¡as ¡s ¡-­‑a-­‑> ¡s’ ¡ L(s) ¡are ¡the ¡atomic ¡proposiOons ¡in ¡AP ¡that ¡are ¡saOsfied ¡in ¡state ¡s. ¡ Given ¡a ¡formula, ¡f,, ¡a ¡state ¡s ¡saOsfies ¡f ¡(i.e., ¡is ¡a ¡model ¡of ¡f) ¡if ¡and ¡only ¡if ¡f ¡ can ¡be ¡derived ¡from ¡the ¡atomic ¡proposiOons ¡associated ¡with ¡state ¡s ¡ via ¡the ¡labeling ¡funcOon ¡L, ¡that ¡is: ¡ s ¡|= ¡f ¡iff ¡L(s) ¡|= ¡f ¡

16

slide-17
SLIDE 17

Toy ¡example ¡again ¡

S ¡= ¡{pay, ¡select, ¡soda, ¡beer} ¡ ¡ I ¡= ¡{pay} ¡ ¡ Act ¡= ¡{insert_coin, ¡get_soda, ¡get_beer, ¡T} ¡

  • ­‑> ¡= ¡{(pay, ¡insert_coin, ¡select), ¡(beer, ¡get_beer, ¡

pay), ¡(soda, ¡get_soda, ¡ay), ¡(select, ¡τ , ¡soda), ¡ (select, ¡τ , ¡beer)} ¡

17

slide-18
SLIDE 18

Atomic ¡proposi7ons ¡in ¡the ¡toy ¡Example ¡ The ¡atomic ¡proposiOons ¡in ¡a ¡ transiOon ¡system ¡are ¡chosen ¡ based ¡on ¡the ¡properOes ¡the ¡ modeler ¡wants ¡to ¡check. ¡

18

Example ¡property ¡to ¡verify: ¡The ¡vending ¡machine ¡only ¡delivers ¡ a ¡drink ¡arer ¡the ¡user ¡pays ¡(inserts ¡a ¡coin). ¡ Relevant ¡atomic ¡proposiOons: ¡AP ¡= ¡{paid, ¡delivered} ¡ ¡ Appropriate ¡Labeling ¡funcOon: ¡ ¡L(pay) ¡= ¡empty ¡set ¡ ¡L(soda)=L(beer)={paid, ¡delivered} ¡ L(select)={paid} ¡

slide-19
SLIDE 19

Using ¡non-­‑determinism ¡to ¡under-­‑ specify ¡a ¡problem ¡

  • The ¡toy ¡model ¡is ¡non-­‑determinisOc: ¡When ¡the ¡system ¡

enters ¡the ¡“select” ¡state, ¡the ¡transiOon ¡system ¡non-­‑ determinisOcally ¡chooses ¡to ¡dispense ¡beer ¡or ¡soda ¡(i.e., ¡it ¡ makes ¡a ¡choice ¡that ¡cannot ¡be ¡determined ¡beforehand ¡by ¡ examining ¡the ¡model). ¡

  • In ¡this ¡case ¡the ¡model ¡deliberately ¡abstracts ¡over ¡the ¡

mechanism ¡a ¡vending ¡machine ¡customer ¡uses ¡to ¡select ¡ soda ¡or ¡beer ¡

– In ¡other ¡words, ¡the ¡modeler ¡is ¡leaving ¡open ¡the ¡choice ¡of ¡how ¡ this ¡is ¡done; ¡someone ¡implemenOng ¡the ¡model ¡needs ¡to ¡resolve ¡ this ¡non-­‑determinism ¡to ¡make ¡the ¡system ¡determinisOc ¡

  • Non-­‑determinisOc ¡choice ¡is ¡also ¡used ¡to ¡model ¡concurrent ¡

(parallel) ¡behavior ¡as ¡we ¡will ¡see ¡later. ¡

19

slide-20
SLIDE 20

AcOon-­‑DeterminisOc ¡TS ¡

  • Post(s,act) ¡are ¡all ¡the ¡target ¡states ¡associated ¡

with ¡s ¡via ¡transiOons ¡labeled ¡with ¡act; ¡i.e., ¡ Post(s,act) ¡= ¡{s’: ¡State ¡| ¡s ¡–act-­‑> ¡s’} ¡

  • TS ¡= ¡(S, ¡Act, ¡-­‑>, ¡I, ¡AP, ¡L) ¡is ¡acOon-­‑determinisOc ¡

if ¡ ¡

– #(I) ¡<= ¡1 ¡(# ¡returns ¡the ¡number ¡of ¡elements ¡in ¡its ¡ set ¡argument) ¡ – For ¡all ¡states ¡s ¡in ¡S ¡and ¡acOons ¡act ¡in ¡Act, ¡#(Post (s,act)) ¡<= ¡1, ¡where ¡

20

slide-21
SLIDE 21

AP-­‑DeterminisOc ¡TS ¡

  • Post(s) ¡consists ¡of ¡all ¡the ¡target ¡states ¡

associated ¡with ¡s ¡via ¡transiOons; ¡i.e., ¡Post(s) ¡= ¡ Uact ¡in ¡Act ¡Post(s,act) ¡

  • TS ¡= ¡(S, ¡Act, ¡-­‑>, ¡I, ¡AP, ¡L) ¡is ¡AP-­‑determinisOc ¡if ¡ ¡

– #(I) ¡<= ¡1 ¡ – For ¡all ¡states ¡s ¡in ¡S, ¡and ¡A ¡in ¡2AP, ¡#(Post(s) ¡ intersect ¡{s’:State ¡| ¡L(s’) ¡= ¡A}) ¡<= ¡1 ¡

21

slide-22
SLIDE 22

Observable ¡behavior ¡

  • Oren ¡useful ¡to ¡have ¡behavior ¡that ¡is ¡observable ¡

by ¡external ¡agents ¡be ¡determinisOc ¡

  • Two ¡observable ¡views ¡

– AcOon-­‑based ¡view: ¡only ¡the ¡acOons ¡are ¡observable ¡ ¡ – State-­‑based ¡view: ¡only ¡the ¡states, ¡via ¡the ¡proposiOons ¡ associated ¡with ¡them, ¡are ¡observable ¡

The ¡two ¡noOons ¡of ¡determinisOc ¡behavior ¡discussed ¡ in ¡the ¡previous ¡slides ¡support ¡these ¡views. ¡

22

slide-23
SLIDE 23

ExecuOons ¡of ¡a ¡TS ¡

  • TS ¡ExecuOons ¡formalize ¡the ¡noOon ¡of ¡behavior ¡in ¡a ¡modeled ¡

system ¡

  • A ¡finite ¡execu7on ¡fragment ¡of ¡a ¡TS ¡is ¡a ¡sequence ¡of ¡state ¡
  • transiOons. ¡ ¡

– For ¡example, ¡s0-­‑act1-­‑>s1, ¡s1-­‑act2-­‑>s3, ¡is ¡wrimen ¡as ¡an ¡alternaOng ¡ sequence ¡of ¡states ¡and ¡acOons ¡that ¡ends ¡in ¡a ¡state, ¡s0,act1,s1,act2,s3 ¡

  • An ¡infinite ¡execu7on ¡fragment ¡is ¡an ¡infinite ¡sequence ¡of ¡

transiOons ¡

  • A ¡maximal ¡execu7on ¡fragment ¡is ¡either ¡a ¡finite ¡execuOon ¡

fragment ¡that ¡ends ¡in ¡a ¡final ¡state, ¡or ¡an ¡infinite ¡execuOon ¡

  • fragment. ¡ ¡

– An ¡execuOon ¡fragment ¡is ¡called ¡iniOal ¡if ¡it ¡starts ¡in ¡an ¡iniOal ¡state. ¡

  • An ¡execuOon ¡of ¡a ¡transiOon ¡system ¡is ¡an ¡iniOal ¡maximal ¡

execuOon ¡fragment ¡

23

slide-24
SLIDE 24

ExecuOons ¡of ¡the ¡vending ¡machine ¡

24

Reachability of states: A state in a transition system is reachable if there is an initial finite execution fragment that ends in s.

slide-25
SLIDE 25

Modeling ¡concurrent ¡systems ¡that ¡ manipulate ¡data ¡

  • In ¡sorware ¡the ¡transiOon ¡from ¡one ¡state ¡to ¡

another ¡oren ¡depends ¡on ¡condiOons ¡expressed ¡ in ¡terms ¡of ¡data ¡

– Condi7onal ¡transi7ons ¡are ¡higher-­‑level ¡constructs ¡ used ¡to ¡describe ¡acOons ¡that ¡are ¡performed ¡only ¡ under ¡certain ¡condiOons ¡

  • Models ¡with ¡condiOonal ¡transiOons ¡are ¡called ¡

program ¡graphs ¡

– Program ¡graphs ¡are ¡“higher-­‑level” ¡in ¡that ¡they ¡can ¡be ¡ transformed ¡into ¡TSs ¡(Note: ¡TSs ¡do ¡not ¡have ¡ condi7onal ¡transi7ons) ¡via ¡a ¡process ¡called ¡unfolding ¡

25

slide-26
SLIDE 26

Extended ¡vending ¡machine ¡example ¡

  • Vending ¡machine ¡extended ¡to: ¡

– to ¡maintain ¡informaOon ¡on ¡number ¡of ¡beers ¡and ¡ soda ¡in ¡machine ¡

  • nsoda: ¡variable ¡that ¡stores ¡number ¡of ¡soda ¡in ¡vending ¡

machine ¡at ¡a ¡parOcular ¡Ome ¡

  • nbeer: ¡variable ¡that ¡stores ¡number ¡of ¡beer ¡in ¡vending ¡

machine ¡at ¡a ¡parOcular ¡Ome ¡

– return ¡coins ¡entered ¡by ¡user ¡if ¡product ¡is ¡not ¡ available ¡

  • ret_coin: ¡represents ¡the ¡return ¡coin ¡acOon ¡

26

slide-27
SLIDE 27

Program ¡graph ¡of ¡the ¡extended ¡vending ¡machine ¡

select ¡and ¡start ¡are ¡called ¡loca7ons ¡ nsoda, ¡and ¡nbeer ¡are ¡variables ¡ coin, ¡refill, ¡sget, ¡bget, ¡ret_coin ¡are ¡ac7ons ¡

27

slide-28
SLIDE 28

A ¡simple ¡text ¡representaOon ¡of ¡the ¡ vending ¡machine ¡PG ¡

start: ¡ ¡ ¡coin; ¡go ¡to ¡select ¡ ¡refill{nsoda ¡:= ¡max; ¡nbeer ¡:= ¡max}; ¡go ¡to ¡start ¡ select: ¡ ¡nsoda ¡> ¡0:: ¡sget{nsoda ¡:= ¡nsoda ¡-­‑1}; ¡go ¡to ¡start ¡ ¡nbeer ¡> ¡0:: ¡bget{nbeer ¡:= ¡nbeer-­‑1}; ¡go ¡to ¡start ¡ ¡nsoda ¡= ¡0 ¡and ¡nbeer ¡= ¡0:: ¡ret_coin; ¡go ¡to ¡start ¡

28

slide-29
SLIDE 29

Unfolding ¡the ¡vending ¡machine ¡PG ¡

29 bget sget

slide-30
SLIDE 30

Program ¡Graphs ¡

  • A ¡program ¡graph ¡over ¡a ¡set ¡of ¡typed ¡variables, ¡

Var, ¡consists ¡of ¡nodes ¡represenOng ¡locaOons ¡ and ¡edges ¡represenOng ¡condiOonal ¡transiOons ¡

– In ¡the ¡vending ¡machine ¡example ¡Var ¡= ¡{nsoda, ¡ nbeer} ¡

  • A ¡program ¡graph ¡also ¡defines ¡effects ¡of ¡acOons ¡
  • n ¡the ¡variables ¡

– An ¡effect ¡is ¡a ¡funcOon ¡that ¡takes ¡an ¡acOon ¡and ¡an ¡ assignment ¡of ¡values ¡to ¡variables ¡and ¡returns ¡a ¡ new ¡assignment ¡of ¡values ¡to ¡variables ¡(the ¡new ¡ assignment ¡is ¡the ¡effect ¡of ¡the ¡acOon) ¡

30

slide-31
SLIDE 31

Program ¡Graph ¡(PG): ¡Formal ¡Defini7on ¡

A ¡program ¡graph ¡PG ¡over ¡set ¡Var ¡of ¡typed ¡variables ¡is ¡a ¡tuple ¡ (Loc, ¡Act, ¡Effect,-­‑>, ¡Loc0, ¡g0) ¡where ¡

  • Loc ¡is ¡a ¡set ¡of ¡locaOons ¡and ¡Act ¡is ¡a ¡set ¡of ¡acOons, ¡
  • Effect ¡: ¡Act ¡× ¡Eval(Var) ¡-­‑-­‑> ¡Eval(Var) ¡is ¡the ¡effect ¡funcOon, ¡

– Eval(Var) ¡is ¡the ¡set ¡of ¡assignments ¡of ¡values ¡to ¡variables ¡in ¡Var, ¡ e.g.,{ ¡<nbeer:= ¡10, ¡nsoda:=20>, ¡<nbeer:= ¡1, ¡nsoda:=20>, ¡ <nbeer:=0, ¡nsoda:=4>, ¡…} ¡is ¡the ¡set ¡of ¡assignments ¡when ¡Var ¡= ¡ {nbeer, ¡nsoda} ¡

  • -­‑> ¡⊆ ¡Loc ¡× ¡Cond(Var) ¡× ¡Act ¡× ¡Loc ¡is ¡the ¡condiOonal ¡

transiOon ¡relaOon, ¡

– Cond(Var) ¡is ¡the ¡set ¡of ¡all ¡Boolean ¡condiOons ¡(proposiOons) ¡over ¡ Var ¡

  • Loc0 ¡⊆ ¡Loc ¡is ¡a ¡set ¡of ¡iniOal ¡locaOons, ¡
  • g0 ¡∈ ¡Cond(Var) ¡is ¡the ¡iniOal ¡condiOon. ¡

31

slide-32
SLIDE 32

Vending ¡machine ¡program ¡graph ¡

32

Loc={start, select} Var={nsoda, nbeer} Act={bget, sget, coin, ret_coin, refill} Effect(coin, η) = η Effect(ret_coin, η) = η Effect(sget, η) = η [nsoda’ = nsoda - 1] Effect(bget, η) = η [nbeer’ = nbeer - 1] Effect(refill, η) = η [nsoda’=max, nbeer’=max]

In the above η is an assignment of values to variables in Var η[v’=f(v)] means that the new assignment to variable v is a function, f, of the previous assignment of v and all other variable assignments are unchanged Loc0 = start g0 = nsoda = max and nbeer = max

slide-33
SLIDE 33

TS ¡semanOcs ¡of ¡program ¡graphs ¡

  • The ¡TS ¡is ¡produced ¡by ¡unfolding ¡the ¡program ¡graph ¡

– You ¡can ¡think ¡of ¡unfolding ¡as ¡a ¡representaOon ¡of ¡the ¡ execuOon ¡of ¡a ¡program ¡described ¡by ¡a ¡PG ¡

  • A ¡state ¡consists ¡of ¡a ¡locaOon ¡(a ¡point ¡in ¡the ¡program) ¡

and ¡an ¡assignment ¡of ¡values ¡to ¡variables: ¡<l,η> ¡

  • An ¡iniOal ¡state ¡consists ¡of ¡an ¡iniOal ¡locaOon ¡and ¡an ¡

assignment ¡that ¡saOsfies ¡the ¡condiOon ¡g0 ¡defined ¡in ¡the ¡ PG ¡

– ¡<l0,η> ¡is ¡an ¡iniOal ¡state ¡if ¡l0 ¡is ¡an ¡iniOal ¡locaOon ¡and ¡η|= ¡g0 ¡

  • The ¡proposiOons ¡consists ¡of ¡the ¡locaOons ¡together ¡

with ¡Cond(Var) ¡

– The ¡proposiOon ¡loc ¡is ¡true ¡in ¡any ¡state ¡of ¡the ¡form ¡<loc, ¡ η>, ¡and ¡false ¡otherwise ¡

33

slide-34
SLIDE 34

Transi7on ¡System ¡Seman7cs ¡of ¡a ¡Program ¡Graph ¡

34

slide-35
SLIDE 35

Structured ¡OperaOonal ¡SemanOcs ¡

  • The ¡semanOcs ¡defined ¡previously ¡is ¡an ¡

example ¡of ¡SOS ¡

  • The ¡semanOcs ¡uses ¡inference ¡rules ¡of ¡the ¡form ¡

35

slide-36
SLIDE 36

Using ¡transiOon ¡systems ¡to ¡ model ¡concurrent ¡behavior ¡

36

slide-37
SLIDE 37

Concurrent ¡systems ¡

  • A ¡concurrent ¡(parallel) ¡system ¡consists ¡of ¡

mulOple ¡processes ¡execuOng ¡concurrently ¡(in ¡ parallel). ¡

  • If ¡a ¡concurrent ¡system ¡consists ¡of ¡n ¡processes, ¡

in ¡which ¡each ¡process, ¡proci, ¡is ¡modeled ¡by ¡a ¡ transiOon ¡system ¡TSi, ¡the ¡concurrent ¡system ¡ can ¡be ¡modeled ¡by ¡a ¡transiOon ¡system ¡ TS ¡= ¡TS1 ¡|| ¡TS2 ¡|| ¡… ¡|| ¡Tsn ¡

– where ¡|| ¡is ¡a ¡parallel ¡composiOon ¡operator ¡

37

slide-38
SLIDE 38

Types ¡of ¡parallel ¡composiOon ¡operators ¡

  • Interleaving ¡

– AcOons ¡of ¡concurrent ¡processes ¡are ¡interleaved ¡in ¡a ¡non-­‑determinisOc ¡ manner ¡ – Used ¡to ¡model ¡processes ¡whose ¡behaviors ¡are ¡completely ¡ independent ¡(asynchronous ¡system ¡of ¡processes) ¡

  • Communica7on ¡via ¡shared ¡variables ¡

– A ¡process ¡can ¡influence ¡the ¡behavior ¡of ¡another ¡process ¡by ¡changing ¡ the ¡value ¡of ¡a ¡variable ¡that ¡is ¡shared ¡with ¡the ¡process ¡

  • Handshaking ¡

– Two ¡processes ¡that ¡want ¡to ¡interact ¡must ¡synchronize ¡their ¡acOons ¡ such ¡that ¡they ¡take ¡part ¡in ¡the ¡interacOon ¡at ¡the ¡same ¡Ome ¡

  • Channel ¡systems ¡

– In ¡a ¡channel ¡system ¡processes ¡interact ¡by ¡reading ¡from ¡and ¡wriOng ¡to ¡ channels ¡connecOng ¡them ¡

38

slide-39
SLIDE 39

Interleaving ¡

39

slide-40
SLIDE 40

Interleaving ¡of ¡processes ¡

  • When ¡processes ¡can ¡execute ¡in ¡a ¡completely ¡

independent ¡manner ¡(with ¡no ¡interacOons) ¡one ¡ can ¡view ¡the ¡system ¡of ¡processes ¡as ¡one ¡system ¡ consisOng ¡of ¡the ¡acOons ¡of ¡each ¡process ¡merged ¡ (interleaved) ¡in ¡an ¡arbitrary ¡manner ¡

– In ¡this ¡system ¡concurrency ¡means ¡that ¡the ¡order ¡in ¡ which ¡the ¡acOons ¡are ¡performed ¡does ¡not ¡affect ¡the ¡ final ¡result; ¡i.e., ¡P1.act1;P2.act2 ¡produces ¡the ¡same ¡ result ¡as ¡P2.act2;P1.act1, ¡where ¡Pi.ac7 ¡is ¡an ¡acOon ¡ performed ¡by ¡process ¡Pi ¡(i=1 ¡or ¡i ¡=2) ¡

  • The ¡interleaving ¡view ¡is ¡an ¡abstracOon ¡in ¡which ¡
  • nly ¡one ¡processor ¡is ¡assumed ¡available ¡to ¡

execute ¡the ¡processes ¡

40

slide-41
SLIDE 41

Interleaving ¡of ¡Traffic ¡Light ¡Transi7on ¡Systems ¡

41

Consider a system with two traffic lights, each modeled by a transition system Interleaved System

Interleaving operator: |||

slide-42
SLIDE 42

Effect ¡of ¡an ¡interleaving ¡operator ¡

42

The above states that the order in which the actions α, β are performed does not matter. ||| is the interleaving operator ; is sequential composition + represents non-deterministic choice

slide-43
SLIDE 43

43

Note that variables are not shared across processes

Effect ¡of ¡an ¡interleaving ¡operator: ¡An ¡ example ¡

slide-44
SLIDE 44

Formal ¡definiOon ¡of ¡interleaving ¡

  • perator ¡

44

slide-45
SLIDE 45

CommunicaOon ¡via ¡Shared ¡ Variables ¡

45

slide-46
SLIDE 46

Modeling ¡non-­‑asynchronous ¡systems ¡

  • Interleaving ¡operator ¡requires ¡that ¡processes ¡

are ¡completely ¡independent ¡

  • What ¡happens ¡if ¡processes ¡access ¡data ¡that ¡is ¡

globally ¡accessible ¡(global ¡data)? ¡

  • See ¡example ¡on ¡next ¡slide ¡

46

slide-47
SLIDE 47

Interleaving ¡in ¡the ¡presence ¡of ¡shared ¡ variables ¡

47

Consider the program graph describing 2 actions from 2 processes, PG1, PG2, that access a global variable x (locations are omitted to simplify the presentations) α: x := 2 * x β: x := x + 1 (α ||| β) = (x := 2 * x ||| x := y + 1)

TS(PG1) TS(PG2) TS(PG1)|||TS(PG2)

slide-48
SLIDE 48

Modeling ¡processes ¡that ¡access ¡global ¡ variables ¡

  • An ¡interleaving ¡operator, ¡|||, ¡on ¡program ¡

graphs ¡(rather ¡than ¡transiOon ¡systems) ¡is ¡used ¡

– PG1 ¡||| ¡PG2 ¡

  • TS(PG1 ¡||| ¡PG2) ¡describes ¡a ¡TS ¡that ¡treats ¡

shared ¡variables ¡appropriately ¡

  • In ¡general, ¡ ¡

– TS(PG1 ¡||| ¡PG2) ¡≠ ¡TS(PG1) ¡||| ¡TS(PG2) ¡ ¡

48

slide-49
SLIDE 49

Interleaving ¡of ¡Program ¡Graphs ¡

49

slide-50
SLIDE 50

Interleaving ¡of ¡Two ¡Example ¡Program ¡Graphs ¡

50

location conditional transition with assignment action Interleaved PG Transition system for interleaved PG

slide-51
SLIDE 51

Non-­‑determinism ¡

  • Non-­‑determinism ¡in ¡a ¡state ¡of ¡a ¡TS ¡produced ¡by ¡a ¡

interleaved ¡PG ¡can ¡be ¡interpreted ¡in ¡3 ¡ways: ¡

  • 1. As ¡an ¡internal ¡non-­‑determinisOc ¡choice ¡made ¡in ¡the ¡

PG ¡

  • 2. As ¡an ¡interleaving ¡of ¡acOons ¡that ¡access ¡variables ¡

that ¡are ¡not ¡shared ¡(referred ¡to ¡as ¡non-­‑cri7cal ¡ ac7ons) ¡

  • 3. As ¡the ¡resoluOon ¡of ¡a ¡contenOon ¡between ¡acOons ¡of ¡

PG1 ¡and ¡PG2 ¡that ¡access ¡global ¡variables ¡(referred ¡to ¡ as ¡cri7cal ¡ac7ons) ¡

51

slide-52
SLIDE 52

Accessing ¡global ¡variables ¡

  • CriOcal ¡acOons ¡are ¡those ¡that ¡access ¡global ¡

variables ¡

  • Access ¡to ¡global ¡variables ¡needs ¡to ¡be ¡

controlled ¡

– Only ¡one ¡criOcal ¡acOon ¡can ¡access ¡a ¡global ¡ variable ¡at ¡any ¡Ome ¡ – How ¡do ¡we ¡ensure ¡this? ¡The ¡mutual ¡exclusion ¡ problem ¡

52

slide-53
SLIDE 53

Mutual ¡exclusion ¡using ¡semaphores ¡

  • Two ¡processes ¡with ¡criOcal ¡acOons ¡use ¡a ¡shared ¡

variable, ¡y, ¡ ¡called ¡a ¡semaphore ¡to ¡determine ¡ when ¡they ¡can ¡perform ¡their ¡criOcal ¡acOons, ¡i.e., ¡ enter ¡their ¡criOcal ¡secOons. ¡

– y ¡= ¡0 ¡indicates ¡that ¡one ¡process ¡is ¡execuOng ¡its ¡criOcal ¡ acOons ¡(i.e., ¡is ¡in ¡its ¡criOcal ¡secOon), ¡and ¡thus ¡the ¡

  • ther ¡cannot ¡execute ¡its ¡criOcal ¡acOons; ¡The ¡process ¡

that ¡is ¡execuOng ¡its ¡criOcal ¡secOon ¡in ¡essence ¡locks ¡ access ¡to ¡the ¡global ¡variables. ¡ – y ¡= ¡1 ¡indicates ¡that ¡none ¡of ¡the ¡processes ¡are ¡in ¡their ¡ criOcal ¡secOons ¡(access ¡to ¡the ¡global ¡variables ¡is ¡ unlocked) ¡

53

slide-54
SLIDE 54

CriOcal ¡vs. ¡non-­‑criOcal ¡secOons ¡

54

slide-55
SLIDE 55

Program ¡graphs ¡for ¡semaphore-­‑based ¡ mutual ¡exclusion ¡

55

slide-56
SLIDE 56

56

Reachable states

slide-57
SLIDE 57

TS(PG1|||PG2) ¡

57

slide-58
SLIDE 58

Peterson’s ¡mutual ¡exclusion ¡algorithm ¡

  • In ¡the ¡semaphore ¡approach ¡the ¡choice ¡of ¡which ¡

process ¡enters ¡its ¡criOcal ¡secOon ¡is ¡made ¡non-­‑ determinisOcally ¡

– That ¡is, ¡it ¡is ¡up ¡to ¡the ¡implementer ¡of ¡the ¡model ¡to ¡ determine ¡how ¡the ¡next ¡process ¡to ¡enter ¡its ¡criOcal ¡secOon ¡ is ¡determined ¡

  • Peterson’s ¡algorithm ¡makes ¡an ¡explicit ¡choice ¡
  • Uses ¡variables ¡b1, ¡b2, ¡and ¡x ¡

– b1:Boolean ¡-­‑ ¡true ¡if ¡P1 ¡is ¡waiOng ¡to ¡enter ¡its ¡criOcal ¡secOon ¡

  • r ¡is ¡in ¡its ¡criOcal ¡secOon ¡(i.e., ¡b1 ¡= ¡wait1 ¡or ¡crit1) ¡

– b2:Boolean ¡-­‑ ¡true ¡if ¡P2 ¡is ¡waiOng ¡to ¡enter ¡its ¡criOcal ¡secOon ¡ – x:{1,2} ¡-­‑ ¡if ¡x ¡= ¡1 ¡then ¡P1 ¡can ¡enter ¡its ¡criOcal ¡secOon; ¡else ¡(x ¡ = ¡2) ¡P2 ¡can ¡enter ¡its ¡criOcal ¡secOon ¡

58

slide-59
SLIDE 59

59

slide-60
SLIDE 60

TransiOon ¡System ¡

60

slide-61
SLIDE 61

Atomicity ¡

  • The ¡assignment ¡group ¡(bi:=true; ¡x:=i), ¡where ¡i ¡= ¡1 ¡
  • r ¡2, ¡are ¡atomic, ¡i.e., ¡together ¡they ¡are ¡treated ¡as ¡

a ¡single ¡acOon; ¡the ¡individual ¡assignments ¡cannot ¡ be ¡interleaved ¡with ¡other ¡acOons ¡

  • This ¡is ¡not ¡essenOal ¡for ¡Petersen’s ¡algorithm ¡to ¡

work ¡

– Mutual ¡exclusion ¡can ¡also ¡be ¡ensured ¡when ¡the ¡ processes ¡perform ¡these ¡acOons ¡in ¡the ¡given ¡order ¡ – Mutual ¡exclusion ¡is ¡NOT ¡guaranteed ¡if ¡the ¡operaOons ¡ are ¡performed ¡in ¡reverse ¡ ¡order, ¡i.e., ¡(x:=i,; ¡bi:=true) ¡

61

slide-62
SLIDE 62

Example ¡of ¡violaOon ¡of ¡mutual ¡ exclusion ¡

62

slide-63
SLIDE 63

Handshaking ¡

63

slide-64
SLIDE 64

Synchronous ¡interacOons ¡

  • Processes ¡can ¡also ¡interact ¡through ¡a ¡set ¡of ¡

synchronizing ¡acOons, ¡H, ¡called ¡handshake ¡ ac7ons ¡

  • Processes ¡interact ¡only ¡if ¡they ¡all ¡can ¡perform ¡the ¡

same ¡handshake ¡acOon ¡at ¡the ¡same ¡Ome ¡

– i.e., ¡the ¡models ¡must ¡“shake ¡hands” ¡for ¡the ¡ interacOon ¡to ¡take ¡place ¡

  • These ¡acOons ¡may ¡involve ¡the ¡transfer ¡of ¡data ¡

– This ¡transfer ¡will ¡be ¡ignored ¡in ¡the ¡models ¡we ¡ consider, ¡i.e., ¡we ¡are ¡interested ¡only ¡in ¡the ¡occurrence ¡

  • f ¡the ¡handshake ¡and ¡not ¡in ¡the ¡data ¡that ¡is ¡

exchanged ¡

64

slide-65
SLIDE 65

Handshaking ¡(Synchronous ¡Message ¡Passing) ¡

65

slide-66
SLIDE 66

Handshaking ¡forms ¡

66

Empty set of handshake actions reduces to interleaving Models broadcasting communication

slide-67
SLIDE 67

Mutual ¡exclusion ¡using ¡an ¡Arbiter ¡ process ¡

  • Model ¡the ¡semaphore ¡as ¡a ¡separate ¡process, ¡

called ¡an ¡Arbiter ¡

  • Example: ¡TS1 ¡and ¡TS2 ¡are ¡the ¡transiOon ¡

systems ¡of ¡the ¡parallel ¡processes ¡and ¡Arbiter ¡is ¡ the ¡semaphore ¡process ¡

67

slide-68
SLIDE 68

68

slide-69
SLIDE 69

Railroad ¡crossing ¡example ¡

  • Three ¡processes ¡in ¡the ¡system: ¡Train, ¡Gate, ¡
  • Controller. ¡
  • When ¡the ¡Controller ¡receives ¡a ¡signal ¡that ¡a ¡

train ¡is ¡approaching ¡it ¡closes ¡the ¡gate ¡

  • The ¡gate ¡is ¡opened ¡only ¡arer ¡the ¡train ¡has ¡

sent ¡a ¡signal ¡to ¡the ¡Controller ¡indicaOng ¡it ¡has ¡ crossed ¡the ¡road. ¡

69

slide-70
SLIDE 70

70

slide-71
SLIDE 71

71

slide-72
SLIDE 72

Channel ¡Systems ¡

72

slide-73
SLIDE 73

Asynchronous ¡message ¡passing ¡

  • Processes ¡interact ¡by ¡passing ¡informaOon ¡to ¡each ¡
  • ther ¡via ¡channels ¡of ¡finite ¡or ¡infinite ¡capacity ¡

– A ¡channel ¡is ¡like ¡a ¡buffer ¡

  • System ¡thus ¡consists ¡of ¡processes ¡and ¡channels ¡
  • If ¡channel ¡capacity ¡> ¡0 ¡the ¡processes ¡do ¡not ¡need ¡

to ¡wait ¡for ¡a ¡response ¡from ¡receiver ¡when ¡ sending ¡a ¡message ¡

  • If ¡channel ¡capacity ¡is ¡0 ¡then ¡this ¡form ¡of ¡

interacOon ¡reduces ¡to ¡handshaking ¡

  • Each ¡channel ¡can ¡accept ¡messages ¡of ¡a ¡specified ¡

type ¡only ¡

73

slide-74
SLIDE 74

CommunicaOon ¡acOons ¡

74

Processes can perform the following communication actions:

slide-75
SLIDE 75

Formal ¡definiOon ¡

75

slide-76
SLIDE 76

Enabling ¡communicaOon ¡acOons ¡

76

slide-77
SLIDE 77

77

slide-78
SLIDE 78

Example: ¡AlternaOng ¡Bit ¡Protocol ¡

  • System ¡consists ¡of ¡two ¡processes, ¡S ¡(sender), ¡R ¡(receiver) ¡that ¡

communicate ¡over ¡two ¡channels, ¡c, ¡d ¡

  • Channel ¡c ¡is ¡unreliable ¡(“lossy”) ¡in ¡that ¡it ¡can ¡lose ¡messages ¡during ¡

transmission; ¡channel ¡d ¡is ¡perfect ¡

  • The ¡goal ¡of ¡the ¡design ¡is ¡to ¡ensure ¡that ¡data ¡units ¡(datums) ¡transmimed ¡by ¡

S ¡are ¡received ¡by ¡R ¡

– S ¡sends ¡data ¡of ¡the ¡form ¡<m,b>, ¡where ¡m ¡is ¡a ¡message ¡and ¡b ¡is ¡a ¡control ¡bit ¡ that ¡cab ¡be ¡either ¡0 ¡or ¡1 ¡ – S ¡transmits ¡a ¡message ¡and ¡waits ¡for ¡R ¡to ¡acknowledge ¡receipt; ¡if ¡an ¡ acknowledgement ¡is ¡not ¡received ¡within ¡a ¡given ¡Ome ¡S ¡retransmits ¡the ¡ message ¡ – If ¡R ¡receives ¡the ¡message ¡then ¡it ¡sends ¡an ¡acknowledgement ¡consisOng ¡of ¡the ¡ control ¡bit ¡it ¡received ¡

78

slide-79
SLIDE 79

PG ¡for ¡Sender ¡

79

slide-80
SLIDE 80

PG ¡for ¡Receiver, ¡Timer ¡

80

slide-81
SLIDE 81

TS ¡SemanOcs ¡

81

slide-82
SLIDE 82

82

slide-83
SLIDE 83

Coming ¡up ¡

  • Why ¡model ¡and ¡analyze ¡concurrent ¡systems? ¡
  • How ¡can ¡concurrent ¡systems ¡be ¡modeled? ¡
  • How ¡can ¡concurrent ¡systems ¡be ¡analyzed? ¡
  • What ¡tools ¡are ¡available ¡for ¡modeling ¡and ¡

analyzing ¡concurrent ¡systems? ¡

– IntroducOon ¡to ¡Promela/Spin ¡

83