-
Notifications
You must be signed in to change notification settings - Fork 2
/
bakery.maude
210 lines (169 loc) · 8.57 KB
/
bakery.maude
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
--- ____ _
--- | _ \ | |
--- | |_) | __ _| | _____ _ __ _ _
--- | _ < / _` | |/ / _ \ '__| | | |
--- | |_) | (_| | < __/ | | |_| |
--- |____/ \__,_|_|\_\___|_| \__, |
--- Lorenzo V.S. && __/ |
--- María G.M. |___/
mod BAKERY is
protecting NAT .
including CONFIGURATION .
--- Colección de objetos que modelan el sistema
sort GBState .
op [[_]] : Configuration -> GBState .
--- Un proceso puede estar en tres posibles estados:
--- sleep, wait o crit
sort Mode .
ops sleep wait crit : -> Mode .
--- ___ _ ~~ @ Classes @ ~~ C
--- / __| |__ _ ______ ___ ___ L
--- | (__| / _` (_-<_-</ -_|_-< A
--- \___|_\__,_/__/__/\___/__/ S
--- ~~ @ Classes @ ~~ S
--- Clase BProcess modela el comportamiento de un proceso
--- class BProcess | mode: Mode, number: Nat .
--- Atributos:
--- * mode: estado del proceso (sleep, wait, crit)
--- * number: PID del proceso, su identificador
sort BProcess .
subsort BProcess < Cid .
op BProcess : -> BProcess .
op mode:_ : Mode -> Attribute [gather (&)] .
op number:_ : Nat -> Attribute [gather (&)] .
--- Clase Dispenser que modela el comportamiento de un dispatcher
--- class Dispenser | next: Nat, last: Nat .
--- Argumentos:
--- * next: Id del próximo proceso a atender
--- * last: Id del último proceso atendido
sort Dispenser .
subsort Dispenser < Cid .
op Dispenser : -> Dispenser .
op next:_ : Nat -> Attribute [gather (&)] .
op last:_ : Nat -> Attribute [gather (&)] .
--- ___ ~
--- / _ \ _ __ ___ O
--- | (_) | '_ (_-< P
--- \___/| .__/__/ S
--- |_| ~
--- Operación para crear Dispensadores
sort DispenserId .
subsort DispenserId < Oid .
op D_ : Nat -> DispenserId .
--- Operación para crear PIDs (Identificadores de procesos)
sort ProcessId .
subsort ProcessId < Oid .
op P_ : Nat -> ProcessId .
--- VARIABLES
var D : Dispenser .
var Did : DispenserId .
var Pid : ProcessId .
vars X Y Z : Nat .
var Atts : AttributeSet .
var C : Configuration .
var m : Mode .
--- Operación para crear sistemas con un número cualquiera de procesos
--- Default: Dispenser.next = Dispenser.last = 1
op initialAux : Nat -> Configuration .
eq initialAux (0) = < D 0 : Dispenser | next: 1, last: 1 > .
eq initialAux (s X) = (< P (s X) : BProcess | mode: sleep, number: 0 >) (initialAux(X)) .
op initial : Nat -> GBState .
eq initial (X) = [[ initialAux(X) ]] .
--- Devuelve el número de procesos en estado crítico
op critCount : GBState -> Nat .
eq critCount ([[< Did : Dispenser | next: X, last: Y >]]) = 0 .
eq critCount ([[ (< Pid : BProcess | mode: crit, number: X >) C ]]) = 1 + critCount ([[C]]) .
ceq critCount ([[ (< Pid : BProcess | mode: m, number: X >) C ]]) = critCount ([[C]]) if m == sleep or m == wait .
--- R @ RULES @ _ @ RULES @ R
--- U _ _ _ _ | | ___ ___ U
--- L | '_|| || || |/ -_)(_-< L
--- E |_| \_,_||_|\___|/__/ E
--- S @ RULES @ @ RULES @ S
--- BProcess: sleep -> wait
--- Se toma el número de orden disponible (last) en el dispatcher (Dispenser)
--- Dispenser.last++
rl [wake-up] : < Did : Dispenser | next: X, last: Y > < Pid : BProcess | mode: sleep, number: 0 >
=> < Did : Dispenser | next: X, last: s Y > < Pid : BProcess | mode: wait, number: Y > .
--- BProcess.Id == Dispenser.next
--- BProcess: wait -> crit
rl [crit] : < Did : Dispenser | next: X, last: Y > < Pid : BProcess | mode: wait, number: X >
=> < Did : Dispenser | next: X, last: Y > < Pid : BProcess | mode: crit, number: X > .
--- BProcess: crit -> sleep
--- BProcess.number = 0
--- Dispenser.next++
rl [sleep] : < Did : Dispenser | next: X, last: Y > < Pid : BProcess | mode: crit, number: Z >
=> < Did : Dispenser | next: s X, last: Y > < Pid : BProcess | mode: sleep, number: 0 > .
endm
--- ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
--- ||A |||b |||s |||t |||r |||a |||c |||c |||i |||ó |||n ||
--- ||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__||
--- |/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
--- Abstracción del módulo BAKERY:
--- Decrementando en uno los números de orden de todos los procesos (los que no
--- estén en modo sleep, que tendrán número de orden 0), siempre que el valor de
--- next sea mayor que 1
mod ABSTRACT-BAKERY is
including BAKERY .
--- ___ ~
--- / _ \ _ __ ___ O
--- | (_) | '_ (_-< P
--- \___/| .__/__/ S
--- |_| ~
--- VARIABLES
var C : Configuration .
var Did : DispenserId .
var Pid : ProcessId .
vars X Y N Z : Nat .
var m : Mode .
--- Operación auxiliar para decrementar en N los números de orden para los procesos (parámetro "number")
--- Argumentos:
--- Cantidad a decrementar : Nat
--- Lista de Procesos : Configuration
op restaAux : Nat Configuration -> Configuration .
eq restaAux(N, none) = none .
eq restaAux(N, (< Pid : BProcess | mode: m, number: 0 >) C) = < Pid : BProcess | mode: m, number: 0 > restaAux(N, C).
eq restaAux(N, (< Did : Dispenser | next: X, last: Y >) C) = < Did : Dispenser | next: X, last: Y > restaAux(N,C) .
ceq restaAux(N, (< Pid : BProcess | mode: m, number: Z > C)) = < Pid : BProcess | mode: m, number: sd(Z,N) > restaAux(N, C)
if m =/= sleep .
--- Abstracción: decrementando en uno los números de orden de todos los procesos (los que no
--- estén en modo sleep, que tendrán número de orden 0), siempre que el valor de next sea mayor que 1
--- Returns max number in the processes
op maxNumber : Configuration -> Nat .
eq maxNumber (none) = 0 .
eq maxNumber(< Did : Dispenser | next: X, last: Y > C ) = maxNumber(C) .
eq maxNumber (< Pid : BProcess | mode: m, number: Z > C ) = max(Z, maxNumber(C)) .
--- Ecuación que permite la abstracción
ceq [[< Did : Dispenser | next: X, last: Y > C]]
= [[< Did : Dispenser | next: sd(X,1), last: sd(Y,1) > restaAux(1, C)]]
if X > 1 .
--- TEST de la regla
--- [[< D 0 : Dispenser | next: 3,last: 4 > < P 1 : BProcess | mode: sleep,number: 0 > < P 2 : BProcess | mode: sleep,number: 0 > < P 3 : BProcess | mode: wait,number: 3 > < P 4 : BProcess | mode: wait,number: 4 > < P 5 : BProcess | mode: sleep,number: 0 >]]
--- [[< D 0 : Dispenser | next: 1,last: 3 > < P 1 : BProcess | mode: sleep,number: 0 > < P 2 : BProcess | mode: sleep,number: 0 > < P 3 : BProcess | mode: wait,number: 1 > < P 4 : BProcess | mode: wait,number: 2 > < P 5 : BProcess | mode: sleep,number: 0 >]]
--- search in ABSTRACT-BAKERY : [[< D 0 : Dispenser | next: 3,last: 4 > < P 1 : BProcess | mode: sleep,number: 0 > < P 2 : BProcess | mode: sleep,number: 0 > < P 3 : BProcess | mode: wait,number: 3 > < P 4 : BProcess | mode: wait,number: 4 > < P 5 : BProcess | mode: sleep,number: 0 >]] =>* [[< D 0 : Dispenser | next: 1,last: 3 > < P 1 : BProcess | mode: sleep,number: 0 > < P 2 : BProcess | mode: sleep,number: 0 > < P 3 : BProcess | mode: wait,number: 1 > < P 4 : BProcess | mode: wait,number: 2 > < P 5 : BProcess | mode: sleep,number: 0 >]] .
endm
load model-checker.maude
--- Módulo auxiliar para usar el model checker de maude
mod ABSTRACT-BAKERY-PREDS is
protecting ABSTRACT-BAKERY .
including SATISFACTION .
including QID .
--- Colección de objetos que modelan el sistema
subsort GBState < State .
--- VARIABLES
var m : Mode .
vars ID ID1 ID2 : ProcessId .
vars Z N1 N2 : Nat .
var C : Configuration .
--- Un proceso estará en dicho modo
op processInMode : ProcessId Mode -> Prop .
op notInMutex : -> Prop .
eq [[ < ID : BProcess | mode: m, number: Z > C ]] |= processInMode(ID, m) = true .
eq [[ < ID1 : BProcess | mode: crit, number: N1 >
< ID2 : BProcess | mode: crit, number: N2 > C ]] |= notInMutex = true .
endm
mod BAKERY-CHECK is
protecting ABSTRACT-BAKERY-PREDS .
including MODEL-CHECKER .
including LTL-SIMPLIFIER .
endm
eof