Modeling ¡and ¡Analyzing ¡ Concurrent ¡Systems ¡
Robert ¡B. ¡France ¡
1
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?
1
2
3
4
– network ¡applicaOons, ¡data ¡communicaOon ¡protocols, ¡mulOthreaded ¡code, ¡ client-‑server ¡applicaOons ¡
– 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. ¡
5
that ¡should ¡not ¡be ¡allowed ¡(i.e., ¡model ¡is ¡too ¡permissive). ¡
is, ¡model ¡is ¡to ¡restricOve ¡
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: ¡
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
– M ¡has ¡behavior ¡that ¡is ¡allowed ¡by ¡φ ¡ – Check ¡that ¡M ¡is ¡a ¡model ¡of ¡φ ¡
7
produced ¡
checker ¡(model ¡checker ¡ran ¡out ¡of ¡space ¡or ¡Ome) ¡ ¡
8
– 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) ¡
– That ¡is, ¡it ¡checks ¡if ¡the ¡system ¡model ¡is ¡an ¡assignment ¡of ¡ values ¡to ¡variables ¡in ¡the ¡property ¡that ¡makes ¡the ¡property ¡
9
10
11
– Linear ¡model ¡of ¡Ome; ¡no ¡branching ¡in ¡the ¡Omeline ¡over ¡ which ¡behaviors ¡are ¡observed ¡
12
13
– E.g., ¡the ¡state ¡of ¡a ¡traffic ¡light ¡indicates ¡the ¡color ¡of ¡ the ¡light ¡that ¡is ¡illuminated ¡at ¡a ¡point ¡in ¡Ome ¡
14
15
Transitions are associated with action labels that indicate the actions that cause the transition.
it represents an internal activity of the vending machine)
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
17
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} ¡
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). ¡
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 ¡
(parallel) ¡behavior ¡as ¡we ¡will ¡see ¡later. ¡
19
20
21
– AcOon-‑based ¡view: ¡only ¡the ¡acOons ¡are ¡observable ¡ ¡ – State-‑based ¡view: ¡only ¡the ¡states, ¡via ¡the ¡proposiOons ¡ associated ¡with ¡them, ¡are ¡observable ¡
22
system ¡
– 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 ¡
transiOons ¡
fragment ¡that ¡ends ¡in ¡a ¡final ¡state, ¡or ¡an ¡infinite ¡execuOon ¡
– An ¡execuOon ¡fragment ¡is ¡called ¡iniOal ¡if ¡it ¡starts ¡in ¡an ¡iniOal ¡state. ¡
execuOon ¡fragment ¡
23
24
Reachability of states: A state in a transition system is reachable if there is an initial finite execution fragment that ends in s.
– Condi7onal ¡transi7ons ¡are ¡higher-‑level ¡constructs ¡ used ¡to ¡describe ¡acOons ¡that ¡are ¡performed ¡only ¡ under ¡certain ¡condiOons ¡
– 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
machine ¡at ¡a ¡parOcular ¡Ome ¡
machine ¡at ¡a ¡parOcular ¡Ome ¡
26
select ¡and ¡start ¡are ¡called ¡loca7ons ¡ nsoda, ¡and ¡nbeer ¡are ¡variables ¡ coin, ¡refill, ¡sget, ¡bget, ¡ret_coin ¡are ¡ac7ons ¡
27
28
29 bget sget
30
A ¡program ¡graph ¡PG ¡over ¡set ¡Var ¡of ¡typed ¡variables ¡is ¡a ¡tuple ¡ (Loc, ¡Act, ¡Effect,-‑>, ¡Loc0, ¡g0) ¡where ¡
– 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} ¡
transiOon ¡relaOon, ¡
– Cond(Var) ¡is ¡the ¡set ¡of ¡all ¡Boolean ¡condiOons ¡(proposiOons) ¡over ¡ Var ¡
31
32
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
– You ¡can ¡think ¡of ¡unfolding ¡as ¡a ¡representaOon ¡of ¡the ¡ execuOon ¡of ¡a ¡program ¡described ¡by ¡a ¡PG ¡
– ¡<l0,η> ¡is ¡an ¡iniOal ¡state ¡if ¡l0 ¡is ¡an ¡iniOal ¡locaOon ¡and ¡η|= ¡g0 ¡
– The ¡proposiOon ¡loc ¡is ¡true ¡in ¡any ¡state ¡of ¡the ¡form ¡<loc, ¡ η>, ¡and ¡false ¡otherwise ¡
33
34
35
36
37
– AcOons ¡of ¡concurrent ¡processes ¡are ¡interleaved ¡in ¡a ¡non-‑determinisOc ¡ manner ¡ – Used ¡to ¡model ¡processes ¡whose ¡behaviors ¡are ¡completely ¡ independent ¡(asynchronous ¡system ¡of ¡processes) ¡
– A ¡process ¡can ¡influence ¡the ¡behavior ¡of ¡another ¡process ¡by ¡changing ¡ the ¡value ¡of ¡a ¡variable ¡that ¡is ¡shared ¡with ¡the ¡process ¡
– Two ¡processes ¡that ¡want ¡to ¡interact ¡must ¡synchronize ¡their ¡acOons ¡ such ¡that ¡they ¡take ¡part ¡in ¡the ¡interacOon ¡at ¡the ¡same ¡Ome ¡
– In ¡a ¡channel ¡system ¡processes ¡interact ¡by ¡reading ¡from ¡and ¡wriOng ¡to ¡ channels ¡connecOng ¡them ¡
38
39
– 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) ¡
40
41
Consider a system with two traffic lights, each modeled by a transition system Interleaved System
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
43
Note that variables are not shared across processes
44
45
46
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)
48
49
50
location conditional transition with assignment action Interleaved PG Transition system for interleaved PG
PG ¡
that ¡are ¡not ¡shared ¡(referred ¡to ¡as ¡non-‑cri7cal ¡ ac7ons) ¡
PG1 ¡and ¡PG2 ¡that ¡access ¡global ¡variables ¡(referred ¡to ¡ as ¡cri7cal ¡ac7ons) ¡
51
52
– y ¡= ¡0 ¡indicates ¡that ¡one ¡process ¡is ¡execuOng ¡its ¡criOcal ¡ acOons ¡(i.e., ¡is ¡in ¡its ¡criOcal ¡secOon), ¡and ¡thus ¡the ¡
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
54
55
56
Reachable states
57
– That ¡is, ¡it ¡is ¡up ¡to ¡the ¡implementer ¡of ¡the ¡model ¡to ¡ determine ¡how ¡the ¡next ¡process ¡to ¡enter ¡its ¡criOcal ¡secOon ¡ is ¡determined ¡
– b1:Boolean ¡-‑ ¡true ¡if ¡P1 ¡is ¡waiOng ¡to ¡enter ¡its ¡criOcal ¡secOon ¡
– 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
59
60
– 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
62
63
– i.e., ¡the ¡models ¡must ¡“shake ¡hands” ¡for ¡the ¡ interacOon ¡to ¡take ¡place ¡
– This ¡transfer ¡will ¡be ¡ignored ¡in ¡the ¡models ¡we ¡ consider, ¡i.e., ¡we ¡are ¡interested ¡only ¡in ¡the ¡occurrence ¡
exchanged ¡
64
65
66
Empty set of handshake actions reduces to interleaving Models broadcasting communication
67
68
69
70
71
72
– A ¡channel ¡is ¡like ¡a ¡buffer ¡
73
74
Processes can perform the following communication actions:
75
76
77
communicate ¡over ¡two ¡channels, ¡c, ¡d ¡
transmission; ¡channel ¡d ¡is ¡perfect ¡
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
79
80
81
82
83