262
|
1 |
theory PrioG
|
264
|
2 |
imports PrioGDef
|
262
|
3 |
begin
|
|
4 |
|
|
5 |
lemma runing_ready: "runing s \<subseteq> readys s"
|
|
6 |
by (auto simp only:runing_def readys_def)
|
|
7 |
|
|
8 |
lemma wq_v_neq:
|
|
9 |
"cs \<noteq> cs' \<Longrightarrow> wq (V thread cs#s) cs' = wq s cs'"
|
|
10 |
by (auto simp:wq_def Let_def cp_def split:list.splits)
|
|
11 |
|
|
12 |
lemma wq_distinct: "vt step s \<Longrightarrow> distinct (wq s cs)"
|
|
13 |
proof(erule_tac vt.induct, simp add:wq_def)
|
|
14 |
fix s e
|
|
15 |
assume h1: "step s e"
|
|
16 |
and h2: "distinct (wq s cs)"
|
|
17 |
thus "distinct (wq (e # s) cs)"
|
|
18 |
proof(induct rule:step.induct, auto simp: wq_def Let_def split:list.splits)
|
|
19 |
fix thread s
|
|
20 |
assume h1: "(Cs cs, Th thread) \<notin> (depend s)\<^sup>+"
|
|
21 |
and h2: "thread \<in> set (waiting_queue (schs s) cs)"
|
|
22 |
and h3: "thread \<in> runing s"
|
|
23 |
show "False"
|
|
24 |
proof -
|
|
25 |
from h3 have "\<And> cs. thread \<in> set (waiting_queue (schs s) cs) \<Longrightarrow>
|
|
26 |
thread = hd ((waiting_queue (schs s) cs))"
|
|
27 |
by (simp add:runing_def readys_def s_waiting_def wq_def)
|
|
28 |
from this [OF h2] have "thread = hd (waiting_queue (schs s) cs)" .
|
|
29 |
with h2
|
|
30 |
have "(Cs cs, Th thread) \<in> (depend s)"
|
|
31 |
by (simp add:s_depend_def s_holding_def wq_def cs_holding_def)
|
|
32 |
with h1 show False by auto
|
|
33 |
qed
|
|
34 |
next
|
|
35 |
fix thread s a list
|
|
36 |
assume dst: "distinct list"
|
|
37 |
show "distinct (SOME q. distinct q \<and> set q = set list)"
|
|
38 |
proof(rule someI2)
|
|
39 |
from dst show "distinct list \<and> set list = set list" by auto
|
|
40 |
next
|
|
41 |
fix q assume "distinct q \<and> set q = set list"
|
|
42 |
thus "distinct q" by auto
|
|
43 |
qed
|
|
44 |
qed
|
|
45 |
qed
|
|
46 |
|
|
47 |
lemma step_back_vt: "vt ccs (e#s) \<Longrightarrow> vt ccs s"
|
|
48 |
by(ind_cases "vt ccs (e#s)", simp)
|
|
49 |
|
|
50 |
lemma step_back_step: "vt ccs (e#s) \<Longrightarrow> ccs s e"
|
|
51 |
by(ind_cases "vt ccs (e#s)", simp)
|
|
52 |
|
|
53 |
lemma block_pre:
|
|
54 |
fixes thread cs s
|
|
55 |
assumes vt_e: "vt step (e#s)"
|
|
56 |
and s_ni: "thread \<notin> set (wq s cs)"
|
|
57 |
and s_i: "thread \<in> set (wq (e#s) cs)"
|
|
58 |
shows "e = P thread cs"
|
|
59 |
proof -
|
|
60 |
show ?thesis
|
|
61 |
proof(cases e)
|
|
62 |
case (P th cs)
|
|
63 |
with assms
|
|
64 |
show ?thesis
|
|
65 |
by (auto simp:wq_def Let_def split:if_splits)
|
|
66 |
next
|
|
67 |
case (Create th prio)
|
|
68 |
with assms show ?thesis
|
|
69 |
by (auto simp:wq_def Let_def split:if_splits)
|
|
70 |
next
|
|
71 |
case (Exit th)
|
|
72 |
with assms show ?thesis
|
|
73 |
by (auto simp:wq_def Let_def split:if_splits)
|
|
74 |
next
|
|
75 |
case (Set th prio)
|
|
76 |
with assms show ?thesis
|
|
77 |
by (auto simp:wq_def Let_def split:if_splits)
|
|
78 |
next
|
|
79 |
case (V th cs)
|
|
80 |
with assms show ?thesis
|
|
81 |
apply (auto simp:wq_def Let_def split:if_splits)
|
|
82 |
proof -
|
|
83 |
fix q qs
|
|
84 |
assume h1: "thread \<notin> set (waiting_queue (schs s) cs)"
|
|
85 |
and h2: "q # qs = waiting_queue (schs s) cs"
|
|
86 |
and h3: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
|
|
87 |
and vt: "vt step (V th cs # s)"
|
|
88 |
from h1 and h2[symmetric] have "thread \<notin> set (q # qs)" by simp
|
|
89 |
moreover have "thread \<in> set qs"
|
|
90 |
proof -
|
|
91 |
have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
|
|
92 |
proof(rule someI2)
|
|
93 |
from wq_distinct [OF step_back_vt[OF vt], of cs]
|
|
94 |
and h2[symmetric, folded wq_def]
|
|
95 |
show "distinct qs \<and> set qs = set qs" by auto
|
|
96 |
next
|
|
97 |
fix x assume "distinct x \<and> set x = set qs"
|
|
98 |
thus "set x = set qs" by auto
|
|
99 |
qed
|
|
100 |
with h3 show ?thesis by simp
|
|
101 |
qed
|
|
102 |
ultimately show "False" by auto
|
|
103 |
qed
|
|
104 |
qed
|
|
105 |
qed
|
|
106 |
|
|
107 |
lemma p_pre: "\<lbrakk>vt step ((P thread cs)#s)\<rbrakk> \<Longrightarrow>
|
|
108 |
thread \<in> runing s \<and> (Cs cs, Th thread) \<notin> (depend s)^+"
|
|
109 |
apply (ind_cases "vt step ((P thread cs)#s)")
|
|
110 |
apply (ind_cases "step s (P thread cs)")
|
|
111 |
by auto
|
|
112 |
|
|
113 |
lemma abs1:
|
|
114 |
fixes e es
|
|
115 |
assumes ein: "e \<in> set es"
|
|
116 |
and neq: "hd es \<noteq> hd (es @ [x])"
|
|
117 |
shows "False"
|
|
118 |
proof -
|
|
119 |
from ein have "es \<noteq> []" by auto
|
|
120 |
then obtain e ess where "es = e # ess" by (cases es, auto)
|
|
121 |
with neq show ?thesis by auto
|
|
122 |
qed
|
|
123 |
|
|
124 |
lemma q_head: "Q (hd es) \<Longrightarrow> hd es = hd [th\<leftarrow>es . Q th]"
|
|
125 |
by (cases es, auto)
|
|
126 |
|
|
127 |
inductive_cases evt_cons: "vt cs (a#s)"
|
|
128 |
|
|
129 |
lemma abs2:
|
|
130 |
assumes vt: "vt step (e#s)"
|
|
131 |
and inq: "thread \<in> set (wq s cs)"
|
|
132 |
and nh: "thread = hd (wq s cs)"
|
|
133 |
and qt: "thread \<noteq> hd (wq (e#s) cs)"
|
|
134 |
and inq': "thread \<in> set (wq (e#s) cs)"
|
|
135 |
shows "False"
|
|
136 |
proof -
|
|
137 |
from assms show "False"
|
|
138 |
apply (cases e)
|
|
139 |
apply ((simp split:if_splits add:Let_def wq_def)[1])+
|
|
140 |
apply (insert abs1, fast)[1]
|
|
141 |
apply (auto simp:wq_def simp:Let_def split:if_splits list.splits)
|
|
142 |
proof -
|
|
143 |
fix th qs
|
|
144 |
assume vt: "vt step (V th cs # s)"
|
|
145 |
and th_in: "thread \<in> set (SOME q. distinct q \<and> set q = set qs)"
|
|
146 |
and eq_wq: "waiting_queue (schs s) cs = thread # qs"
|
|
147 |
show "False"
|
|
148 |
proof -
|
|
149 |
from wq_distinct[OF step_back_vt[OF vt], of cs]
|
|
150 |
and eq_wq[folded wq_def] have "distinct (thread#qs)" by simp
|
|
151 |
moreover have "thread \<in> set qs"
|
|
152 |
proof -
|
|
153 |
have "set (SOME q. distinct q \<and> set q = set qs) = set qs"
|
|
154 |
proof(rule someI2)
|
|
155 |
from wq_distinct [OF step_back_vt[OF vt], of cs]
|
|
156 |
and eq_wq [folded wq_def]
|
|
157 |
show "distinct qs \<and> set qs = set qs" by auto
|
|
158 |
next
|
|
159 |
fix x assume "distinct x \<and> set x = set qs"
|
|
160 |
thus "set x = set qs" by auto
|
|
161 |
qed
|
|
162 |
with th_in show ?thesis by auto
|
|
163 |
qed
|
|
164 |
ultimately show ?thesis by auto
|
|
165 |
qed
|
|
166 |
qed
|
|
167 |
qed
|
|
168 |
|
|
169 |
lemma vt_moment: "\<And> t. \<lbrakk>vt cs s; t \<le> length s\<rbrakk> \<Longrightarrow> vt cs (moment t s)"
|
|
170 |
proof(induct s, simp)
|
|
171 |
fix a s t
|
|
172 |
assume h: "\<And>t.\<lbrakk>vt cs s; t \<le> length s\<rbrakk> \<Longrightarrow> vt cs (moment t s)"
|
|
173 |
and vt_a: "vt cs (a # s)"
|
|
174 |
and le_t: "t \<le> length (a # s)"
|
|
175 |
show "vt cs (moment t (a # s))"
|
|
176 |
proof(cases "t = length (a#s)")
|
|
177 |
case True
|
|
178 |
from True have "moment t (a#s) = a#s" by simp
|
|
179 |
with vt_a show ?thesis by simp
|
|
180 |
next
|
|
181 |
case False
|
|
182 |
with le_t have le_t1: "t \<le> length s" by simp
|
|
183 |
from vt_a have "vt cs s"
|
|
184 |
by (erule_tac evt_cons, simp)
|
|
185 |
from h [OF this le_t1] have "vt cs (moment t s)" .
|
|
186 |
moreover have "moment t (a#s) = moment t s"
|
|
187 |
proof -
|
|
188 |
from moment_app [OF le_t1, of "[a]"]
|
|
189 |
show ?thesis by simp
|
|
190 |
qed
|
|
191 |
ultimately show ?thesis by auto
|
|
192 |
qed
|
|
193 |
qed
|
|
194 |
|
|
195 |
(* Wrong:
|
|
196 |
lemma \<lbrakk>thread \<in> set (waiting_queue cs1 s); thread \<in> set (waiting_queue cs2 s)\<rbrakk> \<Longrightarrow> cs1 = cs2"
|
|
197 |
*)
|
|
198 |
|
|
199 |
lemma waiting_unique_pre:
|
|
200 |
fixes cs1 cs2 s thread
|
|
201 |
assumes vt: "vt step s"
|
|
202 |
and h11: "thread \<in> set (wq s cs1)"
|
|
203 |
and h12: "thread \<noteq> hd (wq s cs1)"
|
|
204 |
assumes h21: "thread \<in> set (wq s cs2)"
|
|
205 |
and h22: "thread \<noteq> hd (wq s cs2)"
|
|
206 |
and neq12: "cs1 \<noteq> cs2"
|
|
207 |
shows "False"
|
|
208 |
proof -
|
|
209 |
let "?Q cs s" = "thread \<in> set (wq s cs) \<and> thread \<noteq> hd (wq s cs)"
|
|
210 |
from h11 and h12 have q1: "?Q cs1 s" by simp
|
|
211 |
from h21 and h22 have q2: "?Q cs2 s" by simp
|
|
212 |
have nq1: "\<not> ?Q cs1 []" by (simp add:wq_def)
|
|
213 |
have nq2: "\<not> ?Q cs2 []" by (simp add:wq_def)
|
|
214 |
from p_split [of "?Q cs1", OF q1 nq1]
|
|
215 |
obtain t1 where lt1: "t1 < length s"
|
|
216 |
and np1: "\<not>(thread \<in> set (wq (moment t1 s) cs1) \<and>
|
|
217 |
thread \<noteq> hd (wq (moment t1 s) cs1))"
|
|
218 |
and nn1: "(\<forall>i'>t1. thread \<in> set (wq (moment i' s) cs1) \<and>
|
|
219 |
thread \<noteq> hd (wq (moment i' s) cs1))" by auto
|
|
220 |
from p_split [of "?Q cs2", OF q2 nq2]
|
|
221 |
obtain t2 where lt2: "t2 < length s"
|
|
222 |
and np2: "\<not>(thread \<in> set (wq (moment t2 s) cs2) \<and>
|
|
223 |
thread \<noteq> hd (wq (moment t2 s) cs2))"
|
|
224 |
and nn2: "(\<forall>i'>t2. thread \<in> set (wq (moment i' s) cs2) \<and>
|
|
225 |
thread \<noteq> hd (wq (moment i' s) cs2))" by auto
|
|
226 |
show ?thesis
|
|
227 |
proof -
|
|
228 |
{
|
|
229 |
assume lt12: "t1 < t2"
|
|
230 |
let ?t3 = "Suc t2"
|
|
231 |
from lt2 have le_t3: "?t3 \<le> length s" by auto
|
|
232 |
from moment_plus [OF this]
|
|
233 |
obtain e where eq_m: "moment ?t3 s = e#moment t2 s" by auto
|
|
234 |
have "t2 < ?t3" by simp
|
|
235 |
from nn2 [rule_format, OF this] and eq_m
|
|
236 |
have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
|
|
237 |
h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
|
|
238 |
have vt_e: "vt step (e#moment t2 s)"
|
|
239 |
proof -
|
|
240 |
from vt_moment [OF vt le_t3]
|
|
241 |
have "vt step (moment ?t3 s)" .
|
|
242 |
with eq_m show ?thesis by simp
|
|
243 |
qed
|
|
244 |
have ?thesis
|
|
245 |
proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
|
|
246 |
case True
|
|
247 |
from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
|
|
248 |
by auto
|
|
249 |
from abs2 [OF vt_e True eq_th h2 h1]
|
|
250 |
show ?thesis by auto
|
|
251 |
next
|
|
252 |
case False
|
|
253 |
from block_pre [OF vt_e False h1]
|
|
254 |
have "e = P thread cs2" .
|
|
255 |
with vt_e have "vt step ((P thread cs2)# moment t2 s)" by simp
|
|
256 |
from p_pre [OF this] have "thread \<in> runing (moment t2 s)" by simp
|
|
257 |
with runing_ready have "thread \<in> readys (moment t2 s)" by auto
|
|
258 |
with nn1 [rule_format, OF lt12]
|
|
259 |
show ?thesis by (simp add:readys_def s_waiting_def, auto)
|
|
260 |
qed
|
|
261 |
} moreover {
|
|
262 |
assume lt12: "t2 < t1"
|
|
263 |
let ?t3 = "Suc t1"
|
|
264 |
from lt1 have le_t3: "?t3 \<le> length s" by auto
|
|
265 |
from moment_plus [OF this]
|
|
266 |
obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
|
|
267 |
have lt_t3: "t1 < ?t3" by simp
|
|
268 |
from nn1 [rule_format, OF this] and eq_m
|
|
269 |
have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
|
|
270 |
h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
|
|
271 |
have vt_e: "vt step (e#moment t1 s)"
|
|
272 |
proof -
|
|
273 |
from vt_moment [OF vt le_t3]
|
|
274 |
have "vt step (moment ?t3 s)" .
|
|
275 |
with eq_m show ?thesis by simp
|
|
276 |
qed
|
|
277 |
have ?thesis
|
|
278 |
proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
|
|
279 |
case True
|
|
280 |
from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
|
|
281 |
by auto
|
|
282 |
from abs2 [OF vt_e True eq_th h2 h1]
|
|
283 |
show ?thesis by auto
|
|
284 |
next
|
|
285 |
case False
|
|
286 |
from block_pre [OF vt_e False h1]
|
|
287 |
have "e = P thread cs1" .
|
|
288 |
with vt_e have "vt step ((P thread cs1)# moment t1 s)" by simp
|
|
289 |
from p_pre [OF this] have "thread \<in> runing (moment t1 s)" by simp
|
|
290 |
with runing_ready have "thread \<in> readys (moment t1 s)" by auto
|
|
291 |
with nn2 [rule_format, OF lt12]
|
|
292 |
show ?thesis by (simp add:readys_def s_waiting_def, auto)
|
|
293 |
qed
|
|
294 |
} moreover {
|
|
295 |
assume eqt12: "t1 = t2"
|
|
296 |
let ?t3 = "Suc t1"
|
|
297 |
from lt1 have le_t3: "?t3 \<le> length s" by auto
|
|
298 |
from moment_plus [OF this]
|
|
299 |
obtain e where eq_m: "moment ?t3 s = e#moment t1 s" by auto
|
|
300 |
have lt_t3: "t1 < ?t3" by simp
|
|
301 |
from nn1 [rule_format, OF this] and eq_m
|
|
302 |
have h1: "thread \<in> set (wq (e#moment t1 s) cs1)" and
|
|
303 |
h2: "thread \<noteq> hd (wq (e#moment t1 s) cs1)" by auto
|
|
304 |
have vt_e: "vt step (e#moment t1 s)"
|
|
305 |
proof -
|
|
306 |
from vt_moment [OF vt le_t3]
|
|
307 |
have "vt step (moment ?t3 s)" .
|
|
308 |
with eq_m show ?thesis by simp
|
|
309 |
qed
|
|
310 |
have ?thesis
|
|
311 |
proof(cases "thread \<in> set (wq (moment t1 s) cs1)")
|
|
312 |
case True
|
|
313 |
from True and np1 have eq_th: "thread = hd (wq (moment t1 s) cs1)"
|
|
314 |
by auto
|
|
315 |
from abs2 [OF vt_e True eq_th h2 h1]
|
|
316 |
show ?thesis by auto
|
|
317 |
next
|
|
318 |
case False
|
|
319 |
from block_pre [OF vt_e False h1]
|
|
320 |
have eq_e1: "e = P thread cs1" .
|
|
321 |
have lt_t3: "t1 < ?t3" by simp
|
|
322 |
with eqt12 have "t2 < ?t3" by simp
|
|
323 |
from nn2 [rule_format, OF this] and eq_m and eqt12
|
|
324 |
have h1: "thread \<in> set (wq (e#moment t2 s) cs2)" and
|
|
325 |
h2: "thread \<noteq> hd (wq (e#moment t2 s) cs2)" by auto
|
|
326 |
show ?thesis
|
|
327 |
proof(cases "thread \<in> set (wq (moment t2 s) cs2)")
|
|
328 |
case True
|
|
329 |
from True and np2 have eq_th: "thread = hd (wq (moment t2 s) cs2)"
|
|
330 |
by auto
|
|
331 |
from vt_e and eqt12 have "vt step (e#moment t2 s)" by simp
|
|
332 |
from abs2 [OF this True eq_th h2 h1]
|
|
333 |
show ?thesis .
|
|
334 |
next
|
|
335 |
case False
|
|
336 |
have vt_e: "vt step (e#moment t2 s)"
|
|
337 |
proof -
|
|
338 |
from vt_moment [OF vt le_t3] eqt12
|
|
339 |
have "vt step (moment (Suc t2) s)" by auto
|
|
340 |
with eq_m eqt12 show ?thesis by simp
|
|
341 |
qed
|
|
342 |
from block_pre [OF vt_e False h1]
|
|
343 |
have "e = P thread cs2" .
|
|
344 |
with eq_e1 neq12 show ?thesis by auto
|
|
345 |
qed
|
|
346 |
qed
|
|
347 |
} ultimately show ?thesis by arith
|
|
348 |
qed
|
|
349 |
qed
|
|
350 |
|
|
351 |
lemma waiting_unique:
|
264
|
352 |
fixes s cs1 cs2
|
262
|
353 |
assumes "vt step s"
|
|
354 |
and "waiting s th cs1"
|
|
355 |
and "waiting s th cs2"
|
|
356 |
shows "cs1 = cs2"
|
|
357 |
proof -
|
|
358 |
from waiting_unique_pre and prems
|
|
359 |
show ?thesis
|
|
360 |
by (auto simp add:s_waiting_def)
|
|
361 |
qed
|
|
362 |
|
264
|
363 |
lemma held_unique:
|
262
|
364 |
assumes "vt step s"
|
|
365 |
and "holding s th1 cs"
|
|
366 |
and "holding s th2 cs"
|
|
367 |
shows "th1 = th2"
|
|
368 |
proof -
|
|
369 |
from prems show ?thesis
|
|
370 |
unfolding s_holding_def
|
|
371 |
by auto
|
|
372 |
qed
|
|
373 |
|
|
374 |
lemma birthtime_lt: "th \<in> threads s \<Longrightarrow> birthtime th s < length s"
|
|
375 |
apply (induct s, auto)
|
|
376 |
by (case_tac a, auto split:if_splits)
|
|
377 |
|
|
378 |
lemma birthtime_unique:
|
|
379 |
"\<lbrakk>birthtime th1 s = birthtime th2 s; th1 \<in> threads s; th2 \<in> threads s\<rbrakk>
|
|
380 |
\<Longrightarrow> th1 = th2"
|
|
381 |
apply (induct s, auto)
|
|
382 |
by (case_tac a, auto split:if_splits dest:birthtime_lt)
|
|
383 |
|
|
384 |
lemma preced_unique :
|
|
385 |
assumes pcd_eq: "preced th1 s = preced th2 s"
|
|
386 |
and th_in1: "th1 \<in> threads s"
|
|
387 |
and th_in2: " th2 \<in> threads s"
|
|
388 |
shows "th1 = th2"
|
|
389 |
proof -
|
|
390 |
from pcd_eq have "birthtime th1 s = birthtime th2 s" by (simp add:preced_def)
|
|
391 |
from birthtime_unique [OF this th_in1 th_in2]
|
|
392 |
show ?thesis .
|
|
393 |
qed
|
|
394 |
|
|
395 |
lemma preced_linorder:
|
|
396 |
assumes neq_12: "th1 \<noteq> th2"
|
|
397 |
and th_in1: "th1 \<in> threads s"
|
|
398 |
and th_in2: " th2 \<in> threads s"
|
|
399 |
shows "preced th1 s < preced th2 s \<or> preced th1 s > preced th2 s"
|
|
400 |
proof -
|
|
401 |
from preced_unique [OF _ th_in1 th_in2] and neq_12
|
|
402 |
have "preced th1 s \<noteq> preced th2 s" by auto
|
|
403 |
thus ?thesis by auto
|
|
404 |
qed
|
|
405 |
|
|
406 |
lemma unique_minus:
|
|
407 |
fixes x y z r
|
|
408 |
assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
|
|
409 |
and xy: "(x, y) \<in> r"
|
|
410 |
and xz: "(x, z) \<in> r^+"
|
|
411 |
and neq: "y \<noteq> z"
|
|
412 |
shows "(y, z) \<in> r^+"
|
|
413 |
proof -
|
|
414 |
from xz and neq show ?thesis
|
|
415 |
proof(induct)
|
|
416 |
case (base ya)
|
|
417 |
have "(x, ya) \<in> r" by fact
|
|
418 |
from unique [OF xy this] have "y = ya" .
|
|
419 |
with base show ?case by auto
|
|
420 |
next
|
|
421 |
case (step ya z)
|
|
422 |
show ?case
|
|
423 |
proof(cases "y = ya")
|
|
424 |
case True
|
|
425 |
from step True show ?thesis by simp
|
|
426 |
next
|
|
427 |
case False
|
|
428 |
from step False
|
|
429 |
show ?thesis by auto
|
|
430 |
qed
|
|
431 |
qed
|
|
432 |
qed
|
|
433 |
|
|
434 |
lemma unique_base:
|
|
435 |
fixes r x y z
|
|
436 |
assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
|
|
437 |
and xy: "(x, y) \<in> r"
|
|
438 |
and xz: "(x, z) \<in> r^+"
|
|
439 |
and neq_yz: "y \<noteq> z"
|
|
440 |
shows "(y, z) \<in> r^+"
|
|
441 |
proof -
|
|
442 |
from xz neq_yz show ?thesis
|
|
443 |
proof(induct)
|
|
444 |
case (base ya)
|
|
445 |
from xy unique base show ?case by auto
|
|
446 |
next
|
|
447 |
case (step ya z)
|
|
448 |
show ?case
|
|
449 |
proof(cases "y = ya")
|
|
450 |
case True
|
|
451 |
from True step show ?thesis by auto
|
|
452 |
next
|
|
453 |
case False
|
|
454 |
from False step
|
|
455 |
have "(y, ya) \<in> r\<^sup>+" by auto
|
|
456 |
with step show ?thesis by auto
|
|
457 |
qed
|
|
458 |
qed
|
|
459 |
qed
|
|
460 |
|
|
461 |
lemma unique_chain:
|
|
462 |
fixes r x y z
|
|
463 |
assumes unique: "\<And> a b c. \<lbrakk>(a, b) \<in> r; (a, c) \<in> r\<rbrakk> \<Longrightarrow> b = c"
|
|
464 |
and xy: "(x, y) \<in> r^+"
|
|
465 |
and xz: "(x, z) \<in> r^+"
|
|
466 |
and neq_yz: "y \<noteq> z"
|
|
467 |
shows "(y, z) \<in> r^+ \<or> (z, y) \<in> r^+"
|
|
468 |
proof -
|
|
469 |
from xy xz neq_yz show ?thesis
|
|
470 |
proof(induct)
|
|
471 |
case (base y)
|
|
472 |
have h1: "(x, y) \<in> r" and h2: "(x, z) \<in> r\<^sup>+" and h3: "y \<noteq> z" using base by auto
|
|
473 |
from unique_base [OF _ h1 h2 h3] and unique show ?case by auto
|
|
474 |
next
|
|
475 |
case (step y za)
|
|
476 |
show ?case
|
|
477 |
proof(cases "y = z")
|
|
478 |
case True
|
|
479 |
from True step show ?thesis by auto
|
|
480 |
next
|
|
481 |
case False
|
|
482 |
from False step have "(y, z) \<in> r\<^sup>+ \<or> (z, y) \<in> r\<^sup>+" by auto
|
|
483 |
thus ?thesis
|
|
484 |
proof
|
|
485 |
assume "(z, y) \<in> r\<^sup>+"
|
|
486 |
with step have "(z, za) \<in> r\<^sup>+" by auto
|
|
487 |
thus ?thesis by auto
|
|
488 |
next
|
|
489 |
assume h: "(y, z) \<in> r\<^sup>+"
|
|
490 |
from step have yza: "(y, za) \<in> r" by simp
|
|
491 |
from step have "za \<noteq> z" by simp
|
|
492 |
from unique_minus [OF _ yza h this] and unique
|
|
493 |
have "(za, z) \<in> r\<^sup>+" by auto
|
|
494 |
thus ?thesis by auto
|
|
495 |
qed
|
|
496 |
qed
|
|
497 |
qed
|
|
498 |
qed
|
|
499 |
|
|
500 |
lemma depend_set_unchanged: "(depend (Set th prio # s)) = depend s"
|
|
501 |
apply (unfold s_depend_def s_waiting_def wq_def)
|
|
502 |
by (simp add:Let_def)
|
|
503 |
|
|
504 |
lemma depend_create_unchanged: "(depend (Create th prio # s)) = depend s"
|
|
505 |
apply (unfold s_depend_def s_waiting_def wq_def)
|
|
506 |
by (simp add:Let_def)
|
|
507 |
|
|
508 |
lemma depend_exit_unchanged: "(depend (Exit th # s)) = depend s"
|
|
509 |
apply (unfold s_depend_def s_waiting_def wq_def)
|
|
510 |
by (simp add:Let_def)
|
|
511 |
|
|
512 |
|
|
513 |
|
|
514 |
lemma step_v_hold_inv[elim_format]:
|
|
515 |
"\<And>c t. \<lbrakk>vt step (V th cs # s);
|
|
516 |
\<not> holding (wq s) t c; holding (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> next_th s th cs t \<and> c = cs"
|
|
517 |
proof -
|
|
518 |
fix c t
|
|
519 |
assume vt: "vt step (V th cs # s)"
|
|
520 |
and nhd: "\<not> holding (wq s) t c"
|
|
521 |
and hd: "holding (wq (V th cs # s)) t c"
|
|
522 |
show "next_th s th cs t \<and> c = cs"
|
|
523 |
proof(cases "c = cs")
|
|
524 |
case False
|
|
525 |
with nhd hd show ?thesis
|
|
526 |
by (unfold cs_holding_def wq_def, auto simp:Let_def)
|
|
527 |
next
|
|
528 |
case True
|
|
529 |
with step_back_step [OF vt]
|
|
530 |
have "step s (V th c)" by simp
|
|
531 |
hence "next_th s th cs t"
|
|
532 |
proof(cases)
|
|
533 |
assume "holding s th c"
|
|
534 |
with nhd hd show ?thesis
|
|
535 |
apply (unfold s_holding_def cs_holding_def wq_def next_th_def,
|
|
536 |
auto simp:Let_def split:list.splits if_splits)
|
|
537 |
proof -
|
|
538 |
assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
|
|
539 |
moreover have "\<dots> = set []"
|
|
540 |
proof(rule someI2)
|
|
541 |
show "distinct [] \<and> [] = []" by auto
|
|
542 |
next
|
|
543 |
fix x assume "distinct x \<and> x = []"
|
|
544 |
thus "set x = set []" by auto
|
|
545 |
qed
|
|
546 |
ultimately show False by auto
|
|
547 |
next
|
|
548 |
assume " hd (SOME q. distinct q \<and> q = []) \<in> set (SOME q. distinct q \<and> q = [])"
|
|
549 |
moreover have "\<dots> = set []"
|
|
550 |
proof(rule someI2)
|
|
551 |
show "distinct [] \<and> [] = []" by auto
|
|
552 |
next
|
|
553 |
fix x assume "distinct x \<and> x = []"
|
|
554 |
thus "set x = set []" by auto
|
|
555 |
qed
|
|
556 |
ultimately show False by auto
|
|
557 |
qed
|
|
558 |
qed
|
|
559 |
with True show ?thesis by auto
|
|
560 |
qed
|
|
561 |
qed
|
|
562 |
|
|
563 |
lemma step_v_wait_inv[elim_format]:
|
|
564 |
"\<And>t c. \<lbrakk>vt step (V th cs # s); \<not> waiting (wq (V th cs # s)) t c; waiting (wq s) t c
|
|
565 |
\<rbrakk>
|
|
566 |
\<Longrightarrow> (next_th s th cs t \<and> cs = c)"
|
|
567 |
proof -
|
|
568 |
fix t c
|
|
569 |
assume vt: "vt step (V th cs # s)"
|
|
570 |
and nw: "\<not> waiting (wq (V th cs # s)) t c"
|
|
571 |
and wt: "waiting (wq s) t c"
|
|
572 |
show "next_th s th cs t \<and> cs = c"
|
|
573 |
proof(cases "cs = c")
|
|
574 |
case False
|
|
575 |
with nw wt show ?thesis
|
|
576 |
by (auto simp:cs_waiting_def wq_def Let_def)
|
|
577 |
next
|
|
578 |
case True
|
|
579 |
from nw[folded True] wt[folded True]
|
|
580 |
have "next_th s th cs t"
|
|
581 |
apply (unfold next_th_def, auto simp:cs_waiting_def wq_def Let_def split:list.splits)
|
|
582 |
proof -
|
|
583 |
fix a list
|
|
584 |
assume t_in: "t \<in> set list"
|
|
585 |
and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
|
|
586 |
and eq_wq: "waiting_queue (schs s) cs = a # list"
|
|
587 |
have " set (SOME q. distinct q \<and> set q = set list) = set list"
|
|
588 |
proof(rule someI2)
|
|
589 |
from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq[folded wq_def]
|
|
590 |
show "distinct list \<and> set list = set list" by auto
|
|
591 |
next
|
|
592 |
show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
|
|
593 |
by auto
|
|
594 |
qed
|
|
595 |
with t_ni and t_in show "a = th" by auto
|
|
596 |
next
|
|
597 |
fix a list
|
|
598 |
assume t_in: "t \<in> set list"
|
|
599 |
and t_ni: "t \<notin> set (SOME q. distinct q \<and> set q = set list)"
|
|
600 |
and eq_wq: "waiting_queue (schs s) cs = a # list"
|
|
601 |
have " set (SOME q. distinct q \<and> set q = set list) = set list"
|
|
602 |
proof(rule someI2)
|
|
603 |
from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq[folded wq_def]
|
|
604 |
show "distinct list \<and> set list = set list" by auto
|
|
605 |
next
|
|
606 |
show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
|
|
607 |
by auto
|
|
608 |
qed
|
|
609 |
with t_ni and t_in show "t = hd (SOME q. distinct q \<and> set q = set list)" by auto
|
|
610 |
next
|
|
611 |
fix a list
|
|
612 |
assume eq_wq: "waiting_queue (schs s) cs = a # list"
|
|
613 |
from step_back_step[OF vt]
|
|
614 |
show "a = th"
|
|
615 |
proof(cases)
|
|
616 |
assume "holding s th cs"
|
|
617 |
with eq_wq show ?thesis
|
|
618 |
by (unfold s_holding_def wq_def, auto)
|
|
619 |
qed
|
|
620 |
qed
|
|
621 |
with True show ?thesis by simp
|
|
622 |
qed
|
|
623 |
qed
|
|
624 |
|
|
625 |
lemma step_v_not_wait[consumes 3]:
|
|
626 |
"\<lbrakk>vt step (V th cs # s); next_th s th cs t; waiting (wq (V th cs # s)) t cs\<rbrakk> \<Longrightarrow> False"
|
|
627 |
by (unfold next_th_def cs_waiting_def wq_def, auto simp:Let_def)
|
|
628 |
|
|
629 |
lemma step_v_release:
|
|
630 |
"\<lbrakk>vt step (V th cs # s); holding (wq (V th cs # s)) th cs\<rbrakk> \<Longrightarrow> False"
|
|
631 |
proof -
|
|
632 |
assume vt: "vt step (V th cs # s)"
|
|
633 |
and hd: "holding (wq (V th cs # s)) th cs"
|
|
634 |
from step_back_step [OF vt] and hd
|
|
635 |
show "False"
|
|
636 |
proof(cases)
|
|
637 |
assume "holding (wq (V th cs # s)) th cs" and "holding s th cs"
|
|
638 |
thus ?thesis
|
|
639 |
apply (unfold s_holding_def wq_def cs_holding_def)
|
|
640 |
apply (auto simp:Let_def split:list.splits)
|
|
641 |
proof -
|
|
642 |
fix list
|
|
643 |
assume eq_wq[folded wq_def]:
|
|
644 |
"waiting_queue (schs s) cs = hd (SOME q. distinct q \<and> set q = set list) # list"
|
|
645 |
and hd_in: "hd (SOME q. distinct q \<and> set q = set list)
|
|
646 |
\<in> set (SOME q. distinct q \<and> set q = set list)"
|
|
647 |
have "set (SOME q. distinct q \<and> set q = set list) = set list"
|
|
648 |
proof(rule someI2)
|
|
649 |
from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
|
|
650 |
show "distinct list \<and> set list = set list" by auto
|
|
651 |
next
|
|
652 |
show "\<And>x. distinct x \<and> set x = set list \<Longrightarrow> set x = set list"
|
|
653 |
by auto
|
|
654 |
qed
|
|
655 |
moreover have "distinct (hd (SOME q. distinct q \<and> set q = set list) # list)"
|
|
656 |
proof -
|
|
657 |
from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
|
|
658 |
show ?thesis by auto
|
|
659 |
qed
|
|
660 |
moreover note eq_wq and hd_in
|
|
661 |
ultimately show "False" by auto
|
|
662 |
qed
|
|
663 |
qed
|
|
664 |
qed
|
|
665 |
|
|
666 |
lemma step_v_get_hold:
|
|
667 |
"\<And>th'. \<lbrakk>vt step (V th cs # s); \<not> holding (wq (V th cs # s)) th' cs; next_th s th cs th'\<rbrakk> \<Longrightarrow> False"
|
|
668 |
apply (unfold cs_holding_def next_th_def wq_def,
|
|
669 |
auto simp:Let_def)
|
|
670 |
proof -
|
|
671 |
fix rest
|
|
672 |
assume vt: "vt step (V th cs # s)"
|
|
673 |
and eq_wq[folded wq_def]: " waiting_queue (schs s) cs = th # rest"
|
|
674 |
and nrest: "rest \<noteq> []"
|
|
675 |
and ni: "hd (SOME q. distinct q \<and> set q = set rest)
|
|
676 |
\<notin> set (SOME q. distinct q \<and> set q = set rest)"
|
|
677 |
have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
|
|
678 |
proof(rule someI2)
|
|
679 |
from wq_distinct[OF step_back_vt[OF vt], of cs] and eq_wq
|
|
680 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
681 |
next
|
|
682 |
fix x assume "distinct x \<and> set x = set rest"
|
|
683 |
hence "set x = set rest" by auto
|
|
684 |
with nrest
|
|
685 |
show "x \<noteq> []" by (case_tac x, auto)
|
|
686 |
qed
|
|
687 |
with ni show "False" by auto
|
|
688 |
qed
|
|
689 |
|
|
690 |
lemma step_v_release_inv[elim_format]:
|
|
691 |
"\<And>c t. \<lbrakk>vt step (V th cs # s); \<not> holding (wq (V th cs # s)) t c; holding (wq s) t c\<rbrakk> \<Longrightarrow>
|
|
692 |
c = cs \<and> t = th"
|
|
693 |
apply (unfold cs_holding_def wq_def, auto simp:Let_def split:if_splits list.splits)
|
|
694 |
proof -
|
|
695 |
fix a list
|
|
696 |
assume vt: "vt step (V th cs # s)" and eq_wq: "waiting_queue (schs s) cs = a # list"
|
|
697 |
from step_back_step [OF vt] show "a = th"
|
|
698 |
proof(cases)
|
|
699 |
assume "holding s th cs" with eq_wq
|
|
700 |
show ?thesis
|
|
701 |
by (unfold s_holding_def wq_def, auto)
|
|
702 |
qed
|
|
703 |
next
|
|
704 |
fix a list
|
|
705 |
assume vt: "vt step (V th cs # s)" and eq_wq: "waiting_queue (schs s) cs = a # list"
|
|
706 |
from step_back_step [OF vt] show "a = th"
|
|
707 |
proof(cases)
|
|
708 |
assume "holding s th cs" with eq_wq
|
|
709 |
show ?thesis
|
|
710 |
by (unfold s_holding_def wq_def, auto)
|
|
711 |
qed
|
|
712 |
qed
|
|
713 |
|
|
714 |
lemma step_v_waiting_mono:
|
|
715 |
"\<And>t c. \<lbrakk>vt step (V th cs # s); waiting (wq (V th cs # s)) t c\<rbrakk> \<Longrightarrow> waiting (wq s) t c"
|
|
716 |
proof -
|
|
717 |
fix t c
|
|
718 |
let ?s' = "(V th cs # s)"
|
|
719 |
assume vt: "vt step ?s'"
|
|
720 |
and wt: "waiting (wq ?s') t c"
|
|
721 |
show "waiting (wq s) t c"
|
|
722 |
proof(cases "c = cs")
|
|
723 |
case False
|
|
724 |
assume neq_cs: "c \<noteq> cs"
|
|
725 |
hence "waiting (wq ?s') t c = waiting (wq s) t c"
|
|
726 |
by (unfold cs_waiting_def wq_def, auto simp:Let_def)
|
|
727 |
with wt show ?thesis by simp
|
|
728 |
next
|
|
729 |
case True
|
|
730 |
with wt show ?thesis
|
|
731 |
apply (unfold cs_waiting_def wq_def, auto simp:Let_def split:list.splits)
|
|
732 |
proof -
|
|
733 |
fix a list
|
|
734 |
assume not_in: "t \<notin> set list"
|
|
735 |
and is_in: "t \<in> set (SOME q. distinct q \<and> set q = set list)"
|
|
736 |
and eq_wq: "waiting_queue (schs s) cs = a # list"
|
|
737 |
have "set (SOME q. distinct q \<and> set q = set list) = set list"
|
|
738 |
proof(rule someI2)
|
|
739 |
from wq_distinct [OF step_back_vt[OF vt], of cs]
|
|
740 |
and eq_wq[folded wq_def]
|
|
741 |
show "distinct list \<and> set list = set list" by auto
|
|
742 |
next
|
|
743 |
fix x assume "distinct x \<and> set x = set list"
|
|
744 |
thus "set x = set list" by auto
|
|
745 |
qed
|
|
746 |
with not_in is_in show "t = a" by auto
|
|
747 |
next
|
|
748 |
fix list
|
|
749 |
assume is_waiting: "waiting (wq (V th cs # s)) t cs"
|
|
750 |
and eq_wq: "waiting_queue (schs s) cs = t # list"
|
|
751 |
hence "t \<in> set list"
|
|
752 |
apply (unfold wq_def, auto simp:Let_def cs_waiting_def)
|
|
753 |
proof -
|
|
754 |
assume " t \<in> set (SOME q. distinct q \<and> set q = set list)"
|
|
755 |
moreover have "\<dots> = set list"
|
|
756 |
proof(rule someI2)
|
|
757 |
from wq_distinct [OF step_back_vt[OF vt], of cs]
|
|
758 |
and eq_wq[folded wq_def]
|
|
759 |
show "distinct list \<and> set list = set list" by auto
|
|
760 |
next
|
|
761 |
fix x assume "distinct x \<and> set x = set list"
|
|
762 |
thus "set x = set list" by auto
|
|
763 |
qed
|
|
764 |
ultimately show "t \<in> set list" by simp
|
|
765 |
qed
|
|
766 |
with eq_wq and wq_distinct [OF step_back_vt[OF vt], of cs, unfolded wq_def]
|
|
767 |
show False by auto
|
|
768 |
qed
|
|
769 |
qed
|
|
770 |
qed
|
|
771 |
|
|
772 |
lemma step_depend_v:
|
|
773 |
assumes vt:
|
|
774 |
"vt step (V th cs#s)"
|
|
775 |
shows "
|
|
776 |
depend (V th cs # s) =
|
|
777 |
depend s - {(Cs cs, Th th)} -
|
|
778 |
{(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
|
|
779 |
{(Cs cs, Th th') |th'. next_th s th cs th'}"
|
|
780 |
apply (insert vt, unfold s_depend_def)
|
|
781 |
apply (auto split:if_splits list.splits simp:Let_def)
|
|
782 |
apply (auto elim: step_v_waiting_mono step_v_hold_inv
|
|
783 |
step_v_release step_v_wait_inv
|
|
784 |
step_v_get_hold step_v_release_inv)
|
|
785 |
apply (erule_tac step_v_not_wait, auto)
|
|
786 |
done
|
|
787 |
|
|
788 |
lemma step_depend_p:
|
|
789 |
"vt step (P th cs#s) \<Longrightarrow>
|
|
790 |
depend (P th cs # s) = (if (wq s cs = []) then depend s \<union> {(Cs cs, Th th)}
|
|
791 |
else depend s \<union> {(Th th, Cs cs)})"
|
288
|
792 |
apply(simp only: s_depend_def wq_def)
|
|
793 |
apply (auto split:list.splits prod.splits simp:Let_def wq_def cs_waiting_def cs_holding_def)
|
287
|
794 |
apply(case_tac "csa = cs", auto)
|
262
|
795 |
apply(fold wq_def)
|
|
796 |
apply(drule_tac step_back_step)
|
287
|
797 |
apply(ind_cases " step s (P (hd (wq s cs)) cs)")
|
|
798 |
apply(auto simp:s_depend_def wq_def cs_holding_def)
|
|
799 |
done
|
262
|
800 |
|
|
801 |
lemma simple_A:
|
|
802 |
fixes A
|
|
803 |
assumes h: "\<And> x y. \<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> x = y"
|
|
804 |
shows "A = {} \<or> (\<exists> a. A = {a})"
|
|
805 |
proof(cases "A = {}")
|
|
806 |
case True thus ?thesis by simp
|
|
807 |
next
|
|
808 |
case False then obtain a where "a \<in> A" by auto
|
|
809 |
with h have "A = {a}" by auto
|
|
810 |
thus ?thesis by simp
|
|
811 |
qed
|
|
812 |
|
|
813 |
lemma depend_target_th: "(Th th, x) \<in> depend (s::state) \<Longrightarrow> \<exists> cs. x = Cs cs"
|
|
814 |
by (unfold s_depend_def, auto)
|
|
815 |
|
|
816 |
lemma acyclic_depend:
|
|
817 |
fixes s
|
|
818 |
assumes vt: "vt step s"
|
|
819 |
shows "acyclic (depend s)"
|
|
820 |
proof -
|
|
821 |
from vt show ?thesis
|
|
822 |
proof(induct)
|
|
823 |
case (vt_cons s e)
|
|
824 |
assume ih: "acyclic (depend s)"
|
|
825 |
and stp: "step s e"
|
|
826 |
and vt: "vt step s"
|
|
827 |
show ?case
|
|
828 |
proof(cases e)
|
|
829 |
case (Create th prio)
|
|
830 |
with ih
|
|
831 |
show ?thesis by (simp add:depend_create_unchanged)
|
|
832 |
next
|
|
833 |
case (Exit th)
|
|
834 |
with ih show ?thesis by (simp add:depend_exit_unchanged)
|
|
835 |
next
|
|
836 |
case (V th cs)
|
|
837 |
from V vt stp have vtt: "vt step (V th cs#s)" by auto
|
|
838 |
from step_depend_v [OF this]
|
|
839 |
have eq_de:
|
|
840 |
"depend (e # s) =
|
|
841 |
depend s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
|
|
842 |
{(Cs cs, Th th') |th'. next_th s th cs th'}"
|
|
843 |
(is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
|
|
844 |
from ih have ac: "acyclic (?A - ?B - ?C)" by (auto elim:acyclic_subset)
|
|
845 |
from step_back_step [OF vtt]
|
|
846 |
have "step s (V th cs)" .
|
|
847 |
thus ?thesis
|
|
848 |
proof(cases)
|
|
849 |
assume "holding s th cs"
|
|
850 |
hence th_in: "th \<in> set (wq s cs)" and
|
|
851 |
eq_hd: "th = hd (wq s cs)" by (unfold s_holding_def, auto)
|
|
852 |
then obtain rest where
|
|
853 |
eq_wq: "wq s cs = th#rest"
|
|
854 |
by (cases "wq s cs", auto)
|
|
855 |
show ?thesis
|
|
856 |
proof(cases "rest = []")
|
|
857 |
case False
|
|
858 |
let ?th' = "hd (SOME q. distinct q \<and> set q = set rest)"
|
|
859 |
from eq_wq False have eq_D: "?D = {(Cs cs, Th ?th')}"
|
|
860 |
by (unfold next_th_def, auto)
|
|
861 |
let ?E = "(?A - ?B - ?C)"
|
|
862 |
have "(Th ?th', Cs cs) \<notin> ?E\<^sup>*"
|
|
863 |
proof
|
|
864 |
assume "(Th ?th', Cs cs) \<in> ?E\<^sup>*"
|
|
865 |
hence " (Th ?th', Cs cs) \<in> ?E\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
|
|
866 |
from tranclD [OF this]
|
|
867 |
obtain x where th'_e: "(Th ?th', x) \<in> ?E" by blast
|
|
868 |
hence th_d: "(Th ?th', x) \<in> ?A" by simp
|
|
869 |
from depend_target_th [OF this]
|
|
870 |
obtain cs' where eq_x: "x = Cs cs'" by auto
|
|
871 |
with th_d have "(Th ?th', Cs cs') \<in> ?A" by simp
|
|
872 |
hence wt_th': "waiting s ?th' cs'"
|
|
873 |
unfolding s_depend_def s_waiting_def cs_waiting_def by simp
|
|
874 |
hence "cs' = cs"
|
|
875 |
proof(rule waiting_unique [OF vt])
|
|
876 |
from eq_wq wq_distinct[OF vt, of cs]
|
|
877 |
show "waiting s ?th' cs"
|
|
878 |
apply (unfold s_waiting_def, auto)
|
|
879 |
proof -
|
|
880 |
assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
|
|
881 |
and eq_wq: "wq s cs = th # rest"
|
|
882 |
have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
|
|
883 |
proof(rule someI2)
|
|
884 |
from wq_distinct[OF vt, of cs] and eq_wq
|
|
885 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
886 |
next
|
|
887 |
fix x assume "distinct x \<and> set x = set rest"
|
|
888 |
with False show "x \<noteq> []" by auto
|
|
889 |
qed
|
|
890 |
hence "hd (SOME q. distinct q \<and> set q = set rest) \<in>
|
|
891 |
set (SOME q. distinct q \<and> set q = set rest)" by auto
|
|
892 |
moreover have "\<dots> = set rest"
|
|
893 |
proof(rule someI2)
|
|
894 |
from wq_distinct[OF vt, of cs] and eq_wq
|
|
895 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
896 |
next
|
|
897 |
show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
|
|
898 |
qed
|
|
899 |
moreover note hd_in
|
|
900 |
ultimately show "hd (SOME q. distinct q \<and> set q = set rest) = th" by auto
|
|
901 |
next
|
|
902 |
assume hd_in: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
|
|
903 |
and eq_wq: "wq s cs = hd (SOME q. distinct q \<and> set q = set rest) # rest"
|
|
904 |
have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
|
|
905 |
proof(rule someI2)
|
|
906 |
from wq_distinct[OF vt, of cs] and eq_wq
|
|
907 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
908 |
next
|
|
909 |
fix x assume "distinct x \<and> set x = set rest"
|
|
910 |
with False show "x \<noteq> []" by auto
|
|
911 |
qed
|
|
912 |
hence "hd (SOME q. distinct q \<and> set q = set rest) \<in>
|
|
913 |
set (SOME q. distinct q \<and> set q = set rest)" by auto
|
|
914 |
moreover have "\<dots> = set rest"
|
|
915 |
proof(rule someI2)
|
|
916 |
from wq_distinct[OF vt, of cs] and eq_wq
|
|
917 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
918 |
next
|
|
919 |
show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
|
|
920 |
qed
|
|
921 |
moreover note hd_in
|
|
922 |
ultimately show False by auto
|
|
923 |
qed
|
|
924 |
qed
|
|
925 |
with th'_e eq_x have "(Th ?th', Cs cs) \<in> ?E" by simp
|
|
926 |
with False
|
|
927 |
show "False" by (auto simp: next_th_def eq_wq)
|
|
928 |
qed
|
|
929 |
with acyclic_insert[symmetric] and ac
|
|
930 |
and eq_de eq_D show ?thesis by auto
|
|
931 |
next
|
|
932 |
case True
|
|
933 |
with eq_wq
|
|
934 |
have eq_D: "?D = {}"
|
|
935 |
by (unfold next_th_def, auto)
|
|
936 |
with eq_de ac
|
|
937 |
show ?thesis by auto
|
|
938 |
qed
|
|
939 |
qed
|
|
940 |
next
|
|
941 |
case (P th cs)
|
|
942 |
from P vt stp have vtt: "vt step (P th cs#s)" by auto
|
|
943 |
from step_depend_p [OF this] P
|
|
944 |
have "depend (e # s) =
|
|
945 |
(if wq s cs = [] then depend s \<union> {(Cs cs, Th th)} else
|
|
946 |
depend s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
|
|
947 |
by simp
|
|
948 |
moreover have "acyclic ?R"
|
|
949 |
proof(cases "wq s cs = []")
|
|
950 |
case True
|
|
951 |
hence eq_r: "?R = depend s \<union> {(Cs cs, Th th)}" by simp
|
|
952 |
have "(Th th, Cs cs) \<notin> (depend s)\<^sup>*"
|
|
953 |
proof
|
|
954 |
assume "(Th th, Cs cs) \<in> (depend s)\<^sup>*"
|
|
955 |
hence "(Th th, Cs cs) \<in> (depend s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
|
|
956 |
from tranclD2 [OF this]
|
|
957 |
obtain x where "(x, Cs cs) \<in> depend s" by auto
|
|
958 |
with True show False by (auto simp:s_depend_def cs_waiting_def)
|
|
959 |
qed
|
|
960 |
with acyclic_insert ih eq_r show ?thesis by auto
|
|
961 |
next
|
|
962 |
case False
|
|
963 |
hence eq_r: "?R = depend s \<union> {(Th th, Cs cs)}" by simp
|
|
964 |
have "(Cs cs, Th th) \<notin> (depend s)\<^sup>*"
|
|
965 |
proof
|
|
966 |
assume "(Cs cs, Th th) \<in> (depend s)\<^sup>*"
|
|
967 |
hence "(Cs cs, Th th) \<in> (depend s)\<^sup>+" by (simp add: rtrancl_eq_or_trancl)
|
|
968 |
moreover from step_back_step [OF vtt] have "step s (P th cs)" .
|
|
969 |
ultimately show False
|
|
970 |
proof -
|
|
971 |
show " \<lbrakk>(Cs cs, Th th) \<in> (depend s)\<^sup>+; step s (P th cs)\<rbrakk> \<Longrightarrow> False"
|
|
972 |
by (ind_cases "step s (P th cs)", simp)
|
|
973 |
qed
|
|
974 |
qed
|
|
975 |
with acyclic_insert ih eq_r show ?thesis by auto
|
|
976 |
qed
|
|
977 |
ultimately show ?thesis by simp
|
|
978 |
next
|
|
979 |
case (Set thread prio)
|
|
980 |
with ih
|
|
981 |
thm depend_set_unchanged
|
|
982 |
show ?thesis by (simp add:depend_set_unchanged)
|
|
983 |
qed
|
|
984 |
next
|
|
985 |
case vt_nil
|
|
986 |
show "acyclic (depend ([]::state))"
|
|
987 |
by (auto simp: s_depend_def cs_waiting_def
|
|
988 |
cs_holding_def wq_def acyclic_def)
|
|
989 |
qed
|
|
990 |
qed
|
|
991 |
|
|
992 |
lemma finite_depend:
|
|
993 |
fixes s
|
|
994 |
assumes vt: "vt step s"
|
|
995 |
shows "finite (depend s)"
|
|
996 |
proof -
|
|
997 |
from vt show ?thesis
|
|
998 |
proof(induct)
|
|
999 |
case (vt_cons s e)
|
|
1000 |
assume ih: "finite (depend s)"
|
|
1001 |
and stp: "step s e"
|
|
1002 |
and vt: "vt step s"
|
|
1003 |
show ?case
|
|
1004 |
proof(cases e)
|
|
1005 |
case (Create th prio)
|
|
1006 |
with ih
|
|
1007 |
show ?thesis by (simp add:depend_create_unchanged)
|
|
1008 |
next
|
|
1009 |
case (Exit th)
|
|
1010 |
with ih show ?thesis by (simp add:depend_exit_unchanged)
|
|
1011 |
next
|
|
1012 |
case (V th cs)
|
|
1013 |
from V vt stp have vtt: "vt step (V th cs#s)" by auto
|
|
1014 |
from step_depend_v [OF this]
|
|
1015 |
have eq_de: "depend (e # s) =
|
|
1016 |
depend s - {(Cs cs, Th th)} - {(Th th', Cs cs) |th'. next_th s th cs th'} \<union>
|
|
1017 |
{(Cs cs, Th th') |th'. next_th s th cs th'}
|
|
1018 |
"
|
|
1019 |
(is "?L = (?A - ?B - ?C) \<union> ?D") by (simp add:V)
|
|
1020 |
moreover from ih have ac: "finite (?A - ?B - ?C)" by simp
|
|
1021 |
moreover have "finite ?D"
|
|
1022 |
proof -
|
|
1023 |
have "?D = {} \<or> (\<exists> a. ?D = {a})"
|
|
1024 |
by (unfold next_th_def, auto)
|
|
1025 |
thus ?thesis
|
|
1026 |
proof
|
|
1027 |
assume h: "?D = {}"
|
|
1028 |
show ?thesis by (unfold h, simp)
|
|
1029 |
next
|
|
1030 |
assume "\<exists> a. ?D = {a}"
|
|
1031 |
thus ?thesis by auto
|
|
1032 |
qed
|
|
1033 |
qed
|
|
1034 |
ultimately show ?thesis by simp
|
|
1035 |
next
|
|
1036 |
case (P th cs)
|
|
1037 |
from P vt stp have vtt: "vt step (P th cs#s)" by auto
|
|
1038 |
from step_depend_p [OF this] P
|
|
1039 |
have "depend (e # s) =
|
|
1040 |
(if wq s cs = [] then depend s \<union> {(Cs cs, Th th)} else
|
|
1041 |
depend s \<union> {(Th th, Cs cs)})" (is "?L = ?R")
|
|
1042 |
by simp
|
|
1043 |
moreover have "finite ?R"
|
|
1044 |
proof(cases "wq s cs = []")
|
|
1045 |
case True
|
|
1046 |
hence eq_r: "?R = depend s \<union> {(Cs cs, Th th)}" by simp
|
|
1047 |
with True and ih show ?thesis by auto
|
|
1048 |
next
|
|
1049 |
case False
|
|
1050 |
hence "?R = depend s \<union> {(Th th, Cs cs)}" by simp
|
|
1051 |
with False and ih show ?thesis by auto
|
|
1052 |
qed
|
|
1053 |
ultimately show ?thesis by auto
|
|
1054 |
next
|
|
1055 |
case (Set thread prio)
|
|
1056 |
with ih
|
|
1057 |
show ?thesis by (simp add:depend_set_unchanged)
|
|
1058 |
qed
|
|
1059 |
next
|
|
1060 |
case vt_nil
|
|
1061 |
show "finite (depend ([]::state))"
|
|
1062 |
by (auto simp: s_depend_def cs_waiting_def
|
|
1063 |
cs_holding_def wq_def acyclic_def)
|
|
1064 |
qed
|
|
1065 |
qed
|
|
1066 |
|
|
1067 |
text {* Several useful lemmas *}
|
|
1068 |
|
|
1069 |
lemma wf_dep_converse:
|
|
1070 |
fixes s
|
|
1071 |
assumes vt: "vt step s"
|
|
1072 |
shows "wf ((depend s)^-1)"
|
|
1073 |
proof(rule finite_acyclic_wf_converse)
|
|
1074 |
from finite_depend [OF vt]
|
|
1075 |
show "finite (depend s)" .
|
|
1076 |
next
|
|
1077 |
from acyclic_depend[OF vt]
|
|
1078 |
show "acyclic (depend s)" .
|
|
1079 |
qed
|
|
1080 |
|
|
1081 |
lemma hd_np_in: "x \<in> set l \<Longrightarrow> hd l \<in> set l"
|
|
1082 |
by (induct l, auto)
|
|
1083 |
|
|
1084 |
lemma th_chasing: "(Th th, Cs cs) \<in> depend (s::state) \<Longrightarrow> \<exists> th'. (Cs cs, Th th') \<in> depend s"
|
|
1085 |
by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
|
|
1086 |
|
|
1087 |
lemma wq_threads:
|
|
1088 |
fixes s cs
|
|
1089 |
assumes vt: "vt step s"
|
|
1090 |
and h: "th \<in> set (wq s cs)"
|
|
1091 |
shows "th \<in> threads s"
|
|
1092 |
proof -
|
|
1093 |
from vt and h show ?thesis
|
|
1094 |
proof(induct arbitrary: th cs)
|
|
1095 |
case (vt_cons s e)
|
|
1096 |
assume ih: "\<And>th cs. th \<in> set (wq s cs) \<Longrightarrow> th \<in> threads s"
|
|
1097 |
and stp: "step s e"
|
|
1098 |
and vt: "vt step s"
|
|
1099 |
and h: "th \<in> set (wq (e # s) cs)"
|
|
1100 |
show ?case
|
|
1101 |
proof(cases e)
|
|
1102 |
case (Create th' prio)
|
|
1103 |
with ih h show ?thesis
|
|
1104 |
by (auto simp:wq_def Let_def)
|
|
1105 |
next
|
|
1106 |
case (Exit th')
|
|
1107 |
with stp ih h show ?thesis
|
|
1108 |
apply (auto simp:wq_def Let_def)
|
|
1109 |
apply (ind_cases "step s (Exit th')")
|
|
1110 |
apply (auto simp:runing_def readys_def s_holding_def s_waiting_def holdents_def
|
|
1111 |
s_depend_def s_holding_def cs_holding_def)
|
|
1112 |
by (fold wq_def, auto)
|
|
1113 |
next
|
|
1114 |
case (V th' cs')
|
|
1115 |
show ?thesis
|
|
1116 |
proof(cases "cs' = cs")
|
|
1117 |
case False
|
|
1118 |
with h
|
|
1119 |
show ?thesis
|
|
1120 |
apply(unfold wq_def V, auto simp:Let_def V split:prod.splits, fold wq_def)
|
|
1121 |
by (drule_tac ih, simp)
|
|
1122 |
next
|
|
1123 |
case True
|
|
1124 |
from h
|
|
1125 |
show ?thesis
|
|
1126 |
proof(unfold V wq_def)
|
|
1127 |
assume th_in: "th \<in> set (waiting_queue (schs (V th' cs' # s)) cs)" (is "th \<in> set ?l")
|
|
1128 |
show "th \<in> threads (V th' cs' # s)"
|
|
1129 |
proof(cases "cs = cs'")
|
|
1130 |
case False
|
|
1131 |
hence "?l = waiting_queue (schs s) cs" by (simp add:Let_def)
|
|
1132 |
with th_in have " th \<in> set (wq s cs)"
|
|
1133 |
by (fold wq_def, simp)
|
|
1134 |
from ih [OF this] show ?thesis by simp
|
|
1135 |
next
|
|
1136 |
case True
|
|
1137 |
show ?thesis
|
|
1138 |
proof(cases "waiting_queue (schs s) cs'")
|
|
1139 |
case Nil
|
|
1140 |
with h V show ?thesis
|
|
1141 |
apply (auto simp:wq_def Let_def split:if_splits)
|
|
1142 |
by (fold wq_def, drule_tac ih, simp)
|
|
1143 |
next
|
|
1144 |
case (Cons a rest)
|
|
1145 |
assume eq_wq: "waiting_queue (schs s) cs' = a # rest"
|
|
1146 |
with h V show ?thesis
|
|
1147 |
apply (auto simp:Let_def wq_def split:if_splits)
|
|
1148 |
proof -
|
|
1149 |
assume th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
|
|
1150 |
have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
|
|
1151 |
proof(rule someI2)
|
|
1152 |
from wq_distinct[OF vt, of cs'] and eq_wq[folded wq_def]
|
|
1153 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
1154 |
next
|
|
1155 |
show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
|
|
1156 |
by auto
|
|
1157 |
qed
|
|
1158 |
with eq_wq th_in have "th \<in> set (waiting_queue (schs s) cs')" by auto
|
|
1159 |
from ih[OF this[folded wq_def]] show "th \<in> threads s" .
|
|
1160 |
next
|
|
1161 |
assume th_in: "th \<in> set (waiting_queue (schs s) cs)"
|
|
1162 |
from ih[OF this[folded wq_def]]
|
|
1163 |
show "th \<in> threads s" .
|
|
1164 |
qed
|
|
1165 |
qed
|
|
1166 |
qed
|
|
1167 |
qed
|
|
1168 |
qed
|
|
1169 |
next
|
|
1170 |
case (P th' cs')
|
|
1171 |
from h stp
|
|
1172 |
show ?thesis
|
|
1173 |
apply (unfold P wq_def)
|
|
1174 |
apply (auto simp:Let_def split:if_splits, fold wq_def)
|
|
1175 |
apply (auto intro:ih)
|
|
1176 |
apply(ind_cases "step s (P th' cs')")
|
|
1177 |
by (unfold runing_def readys_def, auto)
|
|
1178 |
next
|
|
1179 |
case (Set thread prio)
|
|
1180 |
with ih h show ?thesis
|
|
1181 |
by (auto simp:wq_def Let_def)
|
|
1182 |
qed
|
|
1183 |
next
|
|
1184 |
case vt_nil
|
|
1185 |
thus ?case by (auto simp:wq_def)
|
|
1186 |
qed
|
|
1187 |
qed
|
|
1188 |
|
|
1189 |
lemma range_in: "\<lbrakk>vt step s; (Th th) \<in> Range (depend (s::state))\<rbrakk> \<Longrightarrow> th \<in> threads s"
|
|
1190 |
apply(unfold s_depend_def cs_waiting_def cs_holding_def)
|
|
1191 |
by (auto intro:wq_threads)
|
|
1192 |
|
|
1193 |
lemma readys_v_eq:
|
|
1194 |
fixes th thread cs rest
|
|
1195 |
assumes vt: "vt step s"
|
|
1196 |
and neq_th: "th \<noteq> thread"
|
|
1197 |
and eq_wq: "wq s cs = thread#rest"
|
|
1198 |
and not_in: "th \<notin> set rest"
|
|
1199 |
shows "(th \<in> readys (V thread cs#s)) = (th \<in> readys s)"
|
|
1200 |
proof -
|
|
1201 |
from prems show ?thesis
|
|
1202 |
apply (auto simp:readys_def)
|
|
1203 |
apply (case_tac "cs = csa", simp add:s_waiting_def)
|
|
1204 |
apply (erule_tac x = csa in allE)
|
|
1205 |
apply (simp add:s_waiting_def wq_def Let_def split:if_splits)
|
|
1206 |
apply (case_tac "csa = cs", simp)
|
|
1207 |
apply (erule_tac x = cs in allE)
|
|
1208 |
apply (auto simp:s_waiting_def wq_def Let_def split:list.splits)
|
|
1209 |
proof -
|
|
1210 |
assume th_nin: "th \<notin> set rest"
|
|
1211 |
and th_in: "th \<in> set (SOME q. distinct q \<and> set q = set rest)"
|
|
1212 |
and eq_wq: "waiting_queue (schs s) cs = thread # rest"
|
|
1213 |
have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
|
|
1214 |
proof(rule someI2)
|
|
1215 |
from wq_distinct[OF vt, of cs] and eq_wq[folded wq_def]
|
|
1216 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
1217 |
next
|
|
1218 |
show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
|
|
1219 |
qed
|
|
1220 |
with th_nin th_in show False by auto
|
|
1221 |
qed
|
|
1222 |
qed
|
|
1223 |
|
|
1224 |
lemma chain_building:
|
|
1225 |
assumes vt: "vt step s"
|
|
1226 |
shows "node \<in> Domain (depend s) \<longrightarrow> (\<exists> th'. th' \<in> readys s \<and> (node, Th th') \<in> (depend s)^+)"
|
|
1227 |
proof -
|
|
1228 |
from wf_dep_converse [OF vt]
|
|
1229 |
have h: "wf ((depend s)\<inverse>)" .
|
|
1230 |
show ?thesis
|
|
1231 |
proof(induct rule:wf_induct [OF h])
|
|
1232 |
fix x
|
|
1233 |
assume ih [rule_format]:
|
|
1234 |
"\<forall>y. (y, x) \<in> (depend s)\<inverse> \<longrightarrow>
|
|
1235 |
y \<in> Domain (depend s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (y, Th th') \<in> (depend s)\<^sup>+)"
|
|
1236 |
show "x \<in> Domain (depend s) \<longrightarrow> (\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (depend s)\<^sup>+)"
|
|
1237 |
proof
|
|
1238 |
assume x_d: "x \<in> Domain (depend s)"
|
|
1239 |
show "\<exists>th'. th' \<in> readys s \<and> (x, Th th') \<in> (depend s)\<^sup>+"
|
|
1240 |
proof(cases x)
|
|
1241 |
case (Th th)
|
|
1242 |
from x_d Th obtain cs where x_in: "(Th th, Cs cs) \<in> depend s" by (auto simp:s_depend_def)
|
|
1243 |
with Th have x_in_r: "(Cs cs, x) \<in> (depend s)^-1" by simp
|
|
1244 |
from th_chasing [OF x_in] obtain th' where "(Cs cs, Th th') \<in> depend s" by blast
|
|
1245 |
hence "Cs cs \<in> Domain (depend s)" by auto
|
|
1246 |
from ih [OF x_in_r this] obtain th'
|
|
1247 |
where th'_ready: " th' \<in> readys s" and cs_in: "(Cs cs, Th th') \<in> (depend s)\<^sup>+" by auto
|
|
1248 |
have "(x, Th th') \<in> (depend s)\<^sup>+" using Th x_in cs_in by auto
|
|
1249 |
with th'_ready show ?thesis by auto
|
|
1250 |
next
|
|
1251 |
case (Cs cs)
|
|
1252 |
from x_d Cs obtain th' where th'_d: "(Th th', x) \<in> (depend s)^-1" by (auto simp:s_depend_def)
|
|
1253 |
show ?thesis
|
|
1254 |
proof(cases "th' \<in> readys s")
|
|
1255 |
case True
|
|
1256 |
from True and th'_d show ?thesis by auto
|
|
1257 |
next
|
|
1258 |
case False
|
|
1259 |
from th'_d and range_in [OF vt] have "th' \<in> threads s" by auto
|
|
1260 |
with False have "Th th' \<in> Domain (depend s)"
|
|
1261 |
by (auto simp:readys_def s_waiting_def s_depend_def cs_waiting_def Domain_def)
|
|
1262 |
from ih [OF th'_d this]
|
|
1263 |
obtain th'' where
|
|
1264 |
th''_r: "th'' \<in> readys s" and
|
|
1265 |
th''_in: "(Th th', Th th'') \<in> (depend s)\<^sup>+" by auto
|
|
1266 |
from th'_d and th''_in
|
|
1267 |
have "(x, Th th'') \<in> (depend s)\<^sup>+" by auto
|
|
1268 |
with th''_r show ?thesis by auto
|
|
1269 |
qed
|
|
1270 |
qed
|
|
1271 |
qed
|
|
1272 |
qed
|
|
1273 |
qed
|
|
1274 |
|
|
1275 |
lemma th_chain_to_ready:
|
|
1276 |
fixes s th
|
|
1277 |
assumes vt: "vt step s"
|
|
1278 |
and th_in: "th \<in> threads s"
|
|
1279 |
shows "th \<in> readys s \<or> (\<exists> th'. th' \<in> readys s \<and> (Th th, Th th') \<in> (depend s)^+)"
|
|
1280 |
proof(cases "th \<in> readys s")
|
|
1281 |
case True
|
|
1282 |
thus ?thesis by auto
|
|
1283 |
next
|
|
1284 |
case False
|
|
1285 |
from False and th_in have "Th th \<in> Domain (depend s)"
|
|
1286 |
by (auto simp:readys_def s_waiting_def s_depend_def cs_waiting_def Domain_def)
|
|
1287 |
from chain_building [rule_format, OF vt this]
|
|
1288 |
show ?thesis by auto
|
|
1289 |
qed
|
|
1290 |
|
|
1291 |
lemma waiting_eq: "waiting s th cs = waiting (wq s) th cs"
|
|
1292 |
by (unfold s_waiting_def cs_waiting_def, auto)
|
|
1293 |
|
|
1294 |
lemma holding_eq: "holding (s::state) th cs = holding (wq s) th cs"
|
|
1295 |
by (unfold s_holding_def cs_holding_def, simp)
|
|
1296 |
|
|
1297 |
lemma holding_unique: "\<lbrakk>holding (s::state) th1 cs; holding s th2 cs\<rbrakk> \<Longrightarrow> th1 = th2"
|
|
1298 |
by (unfold s_holding_def cs_holding_def, auto)
|
|
1299 |
|
|
1300 |
lemma unique_depend: "\<lbrakk>vt step s; (n, n1) \<in> depend s; (n, n2) \<in> depend s\<rbrakk> \<Longrightarrow> n1 = n2"
|
|
1301 |
apply(unfold s_depend_def, auto, fold waiting_eq holding_eq)
|
|
1302 |
by(auto elim:waiting_unique holding_unique)
|
|
1303 |
|
|
1304 |
lemma trancl_split: "(a, b) \<in> r^+ \<Longrightarrow> \<exists> c. (a, c) \<in> r"
|
|
1305 |
by (induct rule:trancl_induct, auto)
|
|
1306 |
|
|
1307 |
lemma dchain_unique:
|
|
1308 |
assumes vt: "vt step s"
|
|
1309 |
and th1_d: "(n, Th th1) \<in> (depend s)^+"
|
|
1310 |
and th1_r: "th1 \<in> readys s"
|
|
1311 |
and th2_d: "(n, Th th2) \<in> (depend s)^+"
|
|
1312 |
and th2_r: "th2 \<in> readys s"
|
|
1313 |
shows "th1 = th2"
|
|
1314 |
proof -
|
|
1315 |
{ assume neq: "th1 \<noteq> th2"
|
|
1316 |
hence "Th th1 \<noteq> Th th2" by simp
|
|
1317 |
from unique_chain [OF _ th1_d th2_d this] and unique_depend [OF vt]
|
|
1318 |
have "(Th th1, Th th2) \<in> (depend s)\<^sup>+ \<or> (Th th2, Th th1) \<in> (depend s)\<^sup>+" by auto
|
|
1319 |
hence "False"
|
|
1320 |
proof
|
|
1321 |
assume "(Th th1, Th th2) \<in> (depend s)\<^sup>+"
|
|
1322 |
from trancl_split [OF this]
|
|
1323 |
obtain n where dd: "(Th th1, n) \<in> depend s" by auto
|
|
1324 |
then obtain cs where eq_n: "n = Cs cs"
|
|
1325 |
by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
|
|
1326 |
from dd eq_n have "th1 \<notin> readys s"
|
|
1327 |
by (auto simp:readys_def s_depend_def s_waiting_def cs_waiting_def)
|
|
1328 |
with th1_r show ?thesis by auto
|
|
1329 |
next
|
|
1330 |
assume "(Th th2, Th th1) \<in> (depend s)\<^sup>+"
|
|
1331 |
from trancl_split [OF this]
|
|
1332 |
obtain n where dd: "(Th th2, n) \<in> depend s" by auto
|
|
1333 |
then obtain cs where eq_n: "n = Cs cs"
|
|
1334 |
by (auto simp:s_depend_def s_holding_def cs_holding_def cs_waiting_def wq_def dest:hd_np_in)
|
|
1335 |
from dd eq_n have "th2 \<notin> readys s"
|
|
1336 |
by (auto simp:readys_def s_depend_def s_waiting_def cs_waiting_def)
|
|
1337 |
with th2_r show ?thesis by auto
|
|
1338 |
qed
|
|
1339 |
} thus ?thesis by auto
|
|
1340 |
qed
|
|
1341 |
|
|
1342 |
|
|
1343 |
lemma step_holdents_p_add:
|
|
1344 |
fixes th cs s
|
|
1345 |
assumes vt: "vt step (P th cs#s)"
|
|
1346 |
and "wq s cs = []"
|
|
1347 |
shows "holdents (P th cs#s) th = holdents s th \<union> {cs}"
|
|
1348 |
proof -
|
|
1349 |
from prems show ?thesis
|
|
1350 |
unfolding holdents_def step_depend_p[OF vt] by auto
|
|
1351 |
qed
|
|
1352 |
|
|
1353 |
lemma step_holdents_p_eq:
|
|
1354 |
fixes th cs s
|
|
1355 |
assumes vt: "vt step (P th cs#s)"
|
|
1356 |
and "wq s cs \<noteq> []"
|
|
1357 |
shows "holdents (P th cs#s) th = holdents s th"
|
|
1358 |
proof -
|
|
1359 |
from prems show ?thesis
|
|
1360 |
unfolding holdents_def step_depend_p[OF vt] by auto
|
|
1361 |
qed
|
|
1362 |
|
|
1363 |
|
|
1364 |
lemma finite_holding:
|
|
1365 |
fixes s th cs
|
|
1366 |
assumes vt: "vt step s"
|
|
1367 |
shows "finite (holdents s th)"
|
|
1368 |
proof -
|
|
1369 |
let ?F = "\<lambda> (x, y). the_cs x"
|
|
1370 |
from finite_depend [OF vt]
|
|
1371 |
have "finite (depend s)" .
|
|
1372 |
hence "finite (?F `(depend s))" by simp
|
|
1373 |
moreover have "{cs . (Cs cs, Th th) \<in> depend s} \<subseteq> \<dots>"
|
|
1374 |
proof -
|
|
1375 |
{ have h: "\<And> a A f. a \<in> A \<Longrightarrow> f a \<in> f ` A" by auto
|
|
1376 |
fix x assume "(Cs x, Th th) \<in> depend s"
|
|
1377 |
hence "?F (Cs x, Th th) \<in> ?F `(depend s)" by (rule h)
|
|
1378 |
moreover have "?F (Cs x, Th th) = x" by simp
|
|
1379 |
ultimately have "x \<in> (\<lambda>(x, y). the_cs x) ` depend s" by simp
|
|
1380 |
} thus ?thesis by auto
|
|
1381 |
qed
|
|
1382 |
ultimately show ?thesis by (unfold holdents_def, auto intro:finite_subset)
|
|
1383 |
qed
|
|
1384 |
|
|
1385 |
lemma cntCS_v_dec:
|
|
1386 |
fixes s thread cs
|
|
1387 |
assumes vtv: "vt step (V thread cs#s)"
|
|
1388 |
shows "(cntCS (V thread cs#s) thread + 1) = cntCS s thread"
|
|
1389 |
proof -
|
|
1390 |
from step_back_step[OF vtv]
|
|
1391 |
have cs_in: "cs \<in> holdents s thread"
|
|
1392 |
apply (cases, unfold holdents_def s_depend_def, simp)
|
|
1393 |
by (unfold cs_holding_def s_holding_def, auto)
|
|
1394 |
moreover have cs_not_in:
|
|
1395 |
"(holdents (V thread cs#s) thread) = holdents s thread - {cs}"
|
|
1396 |
apply (insert wq_distinct[OF step_back_vt[OF vtv], of cs])
|
|
1397 |
apply (unfold holdents_def, unfold step_depend_v[OF vtv],
|
|
1398 |
auto simp:next_th_def)
|
|
1399 |
proof -
|
|
1400 |
fix rest
|
|
1401 |
assume dst: "distinct (rest::thread list)"
|
|
1402 |
and ne: "rest \<noteq> []"
|
|
1403 |
and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
|
|
1404 |
moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
|
|
1405 |
proof(rule someI2)
|
|
1406 |
from dst show "distinct rest \<and> set rest = set rest" by auto
|
|
1407 |
next
|
|
1408 |
show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
|
|
1409 |
qed
|
|
1410 |
ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin>
|
|
1411 |
set (SOME q. distinct q \<and> set q = set rest)" by simp
|
|
1412 |
moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
|
|
1413 |
proof(rule someI2)
|
|
1414 |
from dst show "distinct rest \<and> set rest = set rest" by auto
|
|
1415 |
next
|
|
1416 |
fix x assume " distinct x \<and> set x = set rest" with ne
|
|
1417 |
show "x \<noteq> []" by auto
|
|
1418 |
qed
|
|
1419 |
ultimately
|
|
1420 |
show "(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> depend s"
|
|
1421 |
by auto
|
|
1422 |
next
|
|
1423 |
fix rest
|
|
1424 |
assume dst: "distinct (rest::thread list)"
|
|
1425 |
and ne: "rest \<noteq> []"
|
|
1426 |
and hd_ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
|
|
1427 |
moreover have "set (SOME q. distinct q \<and> set q = set rest) = set rest"
|
|
1428 |
proof(rule someI2)
|
|
1429 |
from dst show "distinct rest \<and> set rest = set rest" by auto
|
|
1430 |
next
|
|
1431 |
show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest" by auto
|
|
1432 |
qed
|
|
1433 |
ultimately have "hd (SOME q. distinct q \<and> set q = set rest) \<notin>
|
|
1434 |
set (SOME q. distinct q \<and> set q = set rest)" by simp
|
|
1435 |
moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
|
|
1436 |
proof(rule someI2)
|
|
1437 |
from dst show "distinct rest \<and> set rest = set rest" by auto
|
|
1438 |
next
|
|
1439 |
fix x assume " distinct x \<and> set x = set rest" with ne
|
|
1440 |
show "x \<noteq> []" by auto
|
|
1441 |
qed
|
|
1442 |
ultimately show "False" by auto
|
|
1443 |
qed
|
|
1444 |
ultimately
|
|
1445 |
have "holdents s thread = insert cs (holdents (V thread cs#s) thread)"
|
|
1446 |
by auto
|
|
1447 |
moreover have "card \<dots> =
|
|
1448 |
Suc (card ((holdents (V thread cs#s) thread) - {cs}))"
|
|
1449 |
proof(rule card_insert)
|
|
1450 |
from finite_holding [OF vtv]
|
|
1451 |
show " finite (holdents (V thread cs # s) thread)" .
|
|
1452 |
qed
|
|
1453 |
moreover from cs_not_in
|
|
1454 |
have "cs \<notin> (holdents (V thread cs#s) thread)" by auto
|
|
1455 |
ultimately show ?thesis by (simp add:cntCS_def)
|
|
1456 |
qed
|
|
1457 |
|
|
1458 |
lemma cnp_cnv_cncs:
|
|
1459 |
fixes s th
|
|
1460 |
assumes vt: "vt step s"
|
|
1461 |
shows "cntP s th = cntV s th + (if (th \<in> readys s \<or> th \<notin> threads s)
|
|
1462 |
then cntCS s th else cntCS s th + 1)"
|
|
1463 |
proof -
|
|
1464 |
from vt show ?thesis
|
|
1465 |
proof(induct arbitrary:th)
|
|
1466 |
case (vt_cons s e)
|
|
1467 |
assume vt: "vt step s"
|
|
1468 |
and ih: "\<And>th. cntP s th = cntV s th +
|
|
1469 |
(if (th \<in> readys s \<or> th \<notin> threads s) then cntCS s th else cntCS s th + 1)"
|
|
1470 |
and stp: "step s e"
|
|
1471 |
from stp show ?case
|
|
1472 |
proof(cases)
|
|
1473 |
case (thread_create thread prio)
|
|
1474 |
assume eq_e: "e = Create thread prio"
|
|
1475 |
and not_in: "thread \<notin> threads s"
|
|
1476 |
show ?thesis
|
|
1477 |
proof -
|
|
1478 |
{ fix cs
|
|
1479 |
assume "thread \<in> set (wq s cs)"
|
|
1480 |
from wq_threads [OF vt this] have "thread \<in> threads s" .
|
|
1481 |
with not_in have "False" by simp
|
|
1482 |
} with eq_e have eq_readys: "readys (e#s) = readys s \<union> {thread}"
|
|
1483 |
by (auto simp:readys_def threads.simps s_waiting_def
|
|
1484 |
wq_def cs_waiting_def Let_def)
|
|
1485 |
from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
|
|
1486 |
from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
|
|
1487 |
have eq_cncs: "cntCS (e#s) th = cntCS s th"
|
|
1488 |
unfolding cntCS_def holdents_def
|
|
1489 |
by (simp add:depend_create_unchanged eq_e)
|
|
1490 |
{ assume "th \<noteq> thread"
|
|
1491 |
with eq_readys eq_e
|
|
1492 |
have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) =
|
|
1493 |
(th \<in> readys (s) \<or> th \<notin> threads (s))"
|
|
1494 |
by (simp add:threads.simps)
|
|
1495 |
with eq_cnp eq_cnv eq_cncs ih not_in
|
|
1496 |
have ?thesis by simp
|
|
1497 |
} moreover {
|
|
1498 |
assume eq_th: "th = thread"
|
|
1499 |
with not_in ih have " cntP s th = cntV s th + cntCS s th" by simp
|
|
1500 |
moreover from eq_th and eq_readys have "th \<in> readys (e#s)" by simp
|
|
1501 |
moreover note eq_cnp eq_cnv eq_cncs
|
|
1502 |
ultimately have ?thesis by auto
|
|
1503 |
} ultimately show ?thesis by blast
|
|
1504 |
qed
|
|
1505 |
next
|
|
1506 |
case (thread_exit thread)
|
|
1507 |
assume eq_e: "e = Exit thread"
|
|
1508 |
and is_runing: "thread \<in> runing s"
|
|
1509 |
and no_hold: "holdents s thread = {}"
|
|
1510 |
from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
|
|
1511 |
from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
|
|
1512 |
have eq_cncs: "cntCS (e#s) th = cntCS s th"
|
|
1513 |
unfolding cntCS_def holdents_def
|
|
1514 |
by (simp add:depend_exit_unchanged eq_e)
|
|
1515 |
{ assume "th \<noteq> thread"
|
|
1516 |
with eq_e
|
|
1517 |
have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) =
|
|
1518 |
(th \<in> readys (s) \<or> th \<notin> threads (s))"
|
|
1519 |
apply (simp add:threads.simps readys_def)
|
|
1520 |
apply (subst s_waiting_def)
|
|
1521 |
apply (subst (1 2) wq_def)
|
|
1522 |
apply (simp add:Let_def)
|
|
1523 |
apply (subst s_waiting_def, simp)
|
|
1524 |
by (fold wq_def, simp)
|
|
1525 |
with eq_cnp eq_cnv eq_cncs ih
|
|
1526 |
have ?thesis by simp
|
|
1527 |
} moreover {
|
|
1528 |
assume eq_th: "th = thread"
|
|
1529 |
with ih is_runing have " cntP s th = cntV s th + cntCS s th"
|
|
1530 |
by (simp add:runing_def)
|
|
1531 |
moreover from eq_th eq_e have "th \<notin> threads (e#s)"
|
|
1532 |
by simp
|
|
1533 |
moreover note eq_cnp eq_cnv eq_cncs
|
|
1534 |
ultimately have ?thesis by auto
|
|
1535 |
} ultimately show ?thesis by blast
|
|
1536 |
next
|
|
1537 |
case (thread_P thread cs)
|
|
1538 |
assume eq_e: "e = P thread cs"
|
|
1539 |
and is_runing: "thread \<in> runing s"
|
|
1540 |
and no_dep: "(Cs cs, Th thread) \<notin> (depend s)\<^sup>+"
|
|
1541 |
from prems have vtp: "vt step (P thread cs#s)" by auto
|
|
1542 |
show ?thesis
|
|
1543 |
proof -
|
|
1544 |
{ have hh: "\<And> A B C. (B = C) \<Longrightarrow> (A \<and> B) = (A \<and> C)" by blast
|
|
1545 |
assume neq_th: "th \<noteq> thread"
|
|
1546 |
with eq_e
|
|
1547 |
have eq_readys: "(th \<in> readys (e#s)) = (th \<in> readys (s))"
|
|
1548 |
apply (simp add:readys_def s_waiting_def wq_def Let_def)
|
|
1549 |
apply (rule_tac hh, clarify)
|
|
1550 |
apply (intro iffI allI, clarify)
|
|
1551 |
apply (erule_tac x = csa in allE, auto)
|
|
1552 |
apply (subgoal_tac "waiting_queue (schs s) cs \<noteq> []", auto)
|
|
1553 |
apply (erule_tac x = cs in allE, auto)
|
|
1554 |
by (case_tac "(waiting_queue (schs s) cs)", auto)
|
|
1555 |
moreover from neq_th eq_e have "cntCS (e # s) th = cntCS s th"
|
|
1556 |
apply (simp add:cntCS_def holdents_def)
|
|
1557 |
by (unfold step_depend_p [OF vtp], auto)
|
|
1558 |
moreover from eq_e neq_th have "cntP (e # s) th = cntP s th"
|
|
1559 |
by (simp add:cntP_def count_def)
|
|
1560 |
moreover from eq_e neq_th have "cntV (e#s) th = cntV s th"
|
|
1561 |
by (simp add:cntV_def count_def)
|
|
1562 |
moreover from eq_e neq_th have "threads (e#s) = threads s" by simp
|
|
1563 |
moreover note ih [of th]
|
|
1564 |
ultimately have ?thesis by simp
|
|
1565 |
} moreover {
|
|
1566 |
assume eq_th: "th = thread"
|
|
1567 |
have ?thesis
|
|
1568 |
proof -
|
|
1569 |
from eq_e eq_th have eq_cnp: "cntP (e # s) th = 1 + (cntP s th)"
|
|
1570 |
by (simp add:cntP_def count_def)
|
|
1571 |
from eq_e eq_th have eq_cnv: "cntV (e#s) th = cntV s th"
|
|
1572 |
by (simp add:cntV_def count_def)
|
|
1573 |
show ?thesis
|
|
1574 |
proof (cases "wq s cs = []")
|
|
1575 |
case True
|
|
1576 |
with is_runing
|
|
1577 |
have "th \<in> readys (e#s)"
|
|
1578 |
apply (unfold eq_e wq_def, unfold readys_def s_depend_def)
|
|
1579 |
apply (simp add: wq_def[symmetric] runing_def eq_th s_waiting_def)
|
|
1580 |
by (auto simp:readys_def wq_def Let_def s_waiting_def wq_def)
|
|
1581 |
moreover have "cntCS (e # s) th = 1 + cntCS s th"
|
|
1582 |
proof -
|
|
1583 |
have "card {csa. csa = cs \<or> (Cs csa, Th thread) \<in> depend s} =
|
|
1584 |
Suc (card {cs. (Cs cs, Th thread) \<in> depend s})" (is "card ?L = Suc (card ?R)")
|
|
1585 |
proof -
|
|
1586 |
have "?L = insert cs ?R" by auto
|
|
1587 |
moreover have "card \<dots> = Suc (card (?R - {cs}))"
|
|
1588 |
proof(rule card_insert)
|
|
1589 |
from finite_holding [OF vt, of thread]
|
|
1590 |
show " finite {cs. (Cs cs, Th thread) \<in> depend s}"
|
|
1591 |
by (unfold holdents_def, simp)
|
|
1592 |
qed
|
|
1593 |
moreover have "?R - {cs} = ?R"
|
|
1594 |
proof -
|
|
1595 |
have "cs \<notin> ?R"
|
|
1596 |
proof
|
|
1597 |
assume "cs \<in> {cs. (Cs cs, Th thread) \<in> depend s}"
|
|
1598 |
with no_dep show False by auto
|
|
1599 |
qed
|
|
1600 |
thus ?thesis by auto
|
|
1601 |
qed
|
|
1602 |
ultimately show ?thesis by auto
|
|
1603 |
qed
|
|
1604 |
thus ?thesis
|
|
1605 |
apply (unfold eq_e eq_th cntCS_def)
|
|
1606 |
apply (simp add: holdents_def)
|
|
1607 |
by (unfold step_depend_p [OF vtp], auto simp:True)
|
|
1608 |
qed
|
|
1609 |
moreover from is_runing have "th \<in> readys s"
|
|
1610 |
by (simp add:runing_def eq_th)
|
|
1611 |
moreover note eq_cnp eq_cnv ih [of th]
|
|
1612 |
ultimately show ?thesis by auto
|
|
1613 |
next
|
|
1614 |
case False
|
|
1615 |
have eq_wq: "wq (e#s) cs = wq s cs @ [th]"
|
|
1616 |
by (unfold eq_th eq_e wq_def, auto simp:Let_def)
|
|
1617 |
have "th \<notin> readys (e#s)"
|
|
1618 |
proof
|
|
1619 |
assume "th \<in> readys (e#s)"
|
|
1620 |
hence "\<forall>cs. \<not> waiting (e # s) th cs" by (simp add:readys_def)
|
|
1621 |
from this[rule_format, of cs] have " \<not> waiting (e # s) th cs" .
|
|
1622 |
hence "th \<in> set (wq (e#s) cs) \<Longrightarrow> th = hd (wq (e#s) cs)"
|
|
1623 |
by (simp add:s_waiting_def)
|
|
1624 |
moreover from eq_wq have "th \<in> set (wq (e#s) cs)" by auto
|
|
1625 |
ultimately have "th = hd (wq (e#s) cs)" by blast
|
|
1626 |
with eq_wq have "th = hd (wq s cs @ [th])" by simp
|
|
1627 |
hence "th = hd (wq s cs)" using False by auto
|
|
1628 |
with False eq_wq wq_distinct [OF vtp, of cs]
|
|
1629 |
show False by (fold eq_e, auto)
|
|
1630 |
qed
|
|
1631 |
moreover from is_runing have "th \<in> threads (e#s)"
|
|
1632 |
by (unfold eq_e, auto simp:runing_def readys_def eq_th)
|
|
1633 |
moreover have "cntCS (e # s) th = cntCS s th"
|
|
1634 |
apply (unfold cntCS_def holdents_def eq_e step_depend_p[OF vtp])
|
|
1635 |
by (auto simp:False)
|
|
1636 |
moreover note eq_cnp eq_cnv ih[of th]
|
|
1637 |
moreover from is_runing have "th \<in> readys s"
|
|
1638 |
by (simp add:runing_def eq_th)
|
|
1639 |
ultimately show ?thesis by auto
|
|
1640 |
qed
|
|
1641 |
qed
|
|
1642 |
} ultimately show ?thesis by blast
|
|
1643 |
qed
|
|
1644 |
next
|
|
1645 |
case (thread_V thread cs)
|
|
1646 |
from prems have vtv: "vt step (V thread cs # s)" by auto
|
|
1647 |
assume eq_e: "e = V thread cs"
|
|
1648 |
and is_runing: "thread \<in> runing s"
|
|
1649 |
and hold: "holding s thread cs"
|
|
1650 |
from hold obtain rest
|
|
1651 |
where eq_wq: "wq s cs = thread # rest"
|
|
1652 |
by (case_tac "wq s cs", auto simp:s_holding_def)
|
|
1653 |
have eq_threads: "threads (e#s) = threads s" by (simp add: eq_e)
|
|
1654 |
have eq_set: "set (SOME q. distinct q \<and> set q = set rest) = set rest"
|
|
1655 |
proof(rule someI2)
|
|
1656 |
from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
|
|
1657 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
1658 |
next
|
|
1659 |
show "\<And>x. distinct x \<and> set x = set rest \<Longrightarrow> set x = set rest"
|
|
1660 |
by auto
|
|
1661 |
qed
|
|
1662 |
show ?thesis
|
|
1663 |
proof -
|
|
1664 |
{ assume eq_th: "th = thread"
|
|
1665 |
from eq_th have eq_cnp: "cntP (e # s) th = cntP s th"
|
|
1666 |
by (unfold eq_e, simp add:cntP_def count_def)
|
|
1667 |
moreover from eq_th have eq_cnv: "cntV (e#s) th = 1 + cntV s th"
|
|
1668 |
by (unfold eq_e, simp add:cntV_def count_def)
|
|
1669 |
moreover from cntCS_v_dec [OF vtv]
|
|
1670 |
have "cntCS (e # s) thread + 1 = cntCS s thread"
|
|
1671 |
by (simp add:eq_e)
|
|
1672 |
moreover from is_runing have rd_before: "thread \<in> readys s"
|
|
1673 |
by (unfold runing_def, simp)
|
|
1674 |
moreover have "thread \<in> readys (e # s)"
|
|
1675 |
proof -
|
|
1676 |
from is_runing
|
|
1677 |
have "thread \<in> threads (e#s)"
|
|
1678 |
by (unfold eq_e, auto simp:runing_def readys_def)
|
|
1679 |
moreover have "\<forall> cs1. \<not> waiting (e#s) thread cs1"
|
|
1680 |
proof
|
|
1681 |
fix cs1
|
|
1682 |
{ assume eq_cs: "cs1 = cs"
|
|
1683 |
have "\<not> waiting (e # s) thread cs1"
|
|
1684 |
proof -
|
|
1685 |
from eq_wq
|
|
1686 |
have "thread \<notin> set (wq (e#s) cs1)"
|
|
1687 |
apply(unfold eq_e wq_def eq_cs s_holding_def)
|
|
1688 |
apply (auto simp:Let_def)
|
|
1689 |
proof -
|
|
1690 |
assume "thread \<in> set (SOME q. distinct q \<and> set q = set rest)"
|
|
1691 |
with eq_set have "thread \<in> set rest" by simp
|
|
1692 |
with wq_distinct[OF step_back_vt[OF vtv], of cs]
|
|
1693 |
and eq_wq show False by auto
|
|
1694 |
qed
|
|
1695 |
thus ?thesis by (simp add:s_waiting_def)
|
|
1696 |
qed
|
|
1697 |
} moreover {
|
|
1698 |
assume neq_cs: "cs1 \<noteq> cs"
|
|
1699 |
have "\<not> waiting (e # s) thread cs1"
|
|
1700 |
proof -
|
|
1701 |
from wq_v_neq [OF neq_cs[symmetric]]
|
|
1702 |
have "wq (V thread cs # s) cs1 = wq s cs1" .
|
|
1703 |
moreover have "\<not> waiting s thread cs1"
|
|
1704 |
proof -
|
|
1705 |
from runing_ready and is_runing
|
|
1706 |
have "thread \<in> readys s" by auto
|
|
1707 |
thus ?thesis by (simp add:readys_def)
|
|
1708 |
qed
|
|
1709 |
ultimately show ?thesis
|
|
1710 |
by (auto simp:s_waiting_def eq_e)
|
|
1711 |
qed
|
|
1712 |
} ultimately show "\<not> waiting (e # s) thread cs1" by blast
|
|
1713 |
qed
|
|
1714 |
ultimately show ?thesis by (simp add:readys_def)
|
|
1715 |
qed
|
|
1716 |
moreover note eq_th ih
|
|
1717 |
ultimately have ?thesis by auto
|
|
1718 |
} moreover {
|
|
1719 |
assume neq_th: "th \<noteq> thread"
|
|
1720 |
from neq_th eq_e have eq_cnp: "cntP (e # s) th = cntP s th"
|
|
1721 |
by (simp add:cntP_def count_def)
|
|
1722 |
from neq_th eq_e have eq_cnv: "cntV (e # s) th = cntV s th"
|
|
1723 |
by (simp add:cntV_def count_def)
|
|
1724 |
have ?thesis
|
|
1725 |
proof(cases "th \<in> set rest")
|
|
1726 |
case False
|
|
1727 |
have "(th \<in> readys (e # s)) = (th \<in> readys s)"
|
|
1728 |
apply (insert step_back_vt[OF vtv])
|
|
1729 |
by (unfold eq_e, rule readys_v_eq [OF _ neq_th eq_wq False], auto)
|
|
1730 |
moreover have "cntCS (e#s) th = cntCS s th"
|
|
1731 |
apply (insert neq_th, unfold eq_e cntCS_def holdents_def step_depend_v[OF vtv], auto)
|
|
1732 |
proof -
|
|
1733 |
have "{csa. (Cs csa, Th th) \<in> depend s \<or> csa = cs \<and> next_th s thread cs th} =
|
|
1734 |
{cs. (Cs cs, Th th) \<in> depend s}"
|
|
1735 |
proof -
|
|
1736 |
from False eq_wq
|
|
1737 |
have " next_th s thread cs th \<Longrightarrow> (Cs cs, Th th) \<in> depend s"
|
|
1738 |
apply (unfold next_th_def, auto)
|
|
1739 |
proof -
|
|
1740 |
assume ne: "rest \<noteq> []"
|
|
1741 |
and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> set rest"
|
|
1742 |
and eq_wq: "wq s cs = thread # rest"
|
|
1743 |
from eq_set ni have "hd (SOME q. distinct q \<and> set q = set rest) \<notin>
|
|
1744 |
set (SOME q. distinct q \<and> set q = set rest)
|
|
1745 |
" by simp
|
|
1746 |
moreover have "(SOME q. distinct q \<and> set q = set rest) \<noteq> []"
|
|
1747 |
proof(rule someI2)
|
|
1748 |
from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
|
|
1749 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
1750 |
next
|
|
1751 |
fix x assume "distinct x \<and> set x = set rest"
|
|
1752 |
with ne show "x \<noteq> []" by auto
|
|
1753 |
qed
|
|
1754 |
ultimately show
|
|
1755 |
"(Cs cs, Th (hd (SOME q. distinct q \<and> set q = set rest))) \<in> depend s"
|
|
1756 |
by auto
|
|
1757 |
qed
|
|
1758 |
thus ?thesis by auto
|
|
1759 |
qed
|
|
1760 |
thus "card {csa. (Cs csa, Th th) \<in> depend s \<or> csa = cs \<and> next_th s thread cs th} =
|
|
1761 |
card {cs. (Cs cs, Th th) \<in> depend s}" by simp
|
|
1762 |
qed
|
|
1763 |
moreover note ih eq_cnp eq_cnv eq_threads
|
|
1764 |
ultimately show ?thesis by auto
|
|
1765 |
next
|
|
1766 |
case True
|
|
1767 |
assume th_in: "th \<in> set rest"
|
|
1768 |
show ?thesis
|
|
1769 |
proof(cases "next_th s thread cs th")
|
|
1770 |
case False
|
|
1771 |
with eq_wq and th_in have
|
|
1772 |
neq_hd: "th \<noteq> hd (SOME q. distinct q \<and> set q = set rest)" (is "th \<noteq> hd ?rest")
|
|
1773 |
by (auto simp:next_th_def)
|
|
1774 |
have "(th \<in> readys (e # s)) = (th \<in> readys s)"
|
|
1775 |
proof -
|
|
1776 |
from eq_wq and th_in
|
|
1777 |
have "\<not> th \<in> readys s"
|
|
1778 |
apply (auto simp:readys_def s_waiting_def)
|
|
1779 |
apply (rule_tac x = cs in exI, auto)
|
|
1780 |
by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto)
|
|
1781 |
moreover
|
|
1782 |
from eq_wq and th_in and neq_hd
|
|
1783 |
have "\<not> (th \<in> readys (e # s))"
|
|
1784 |
apply (auto simp:readys_def s_waiting_def eq_e wq_def Let_def split:list.splits)
|
|
1785 |
by (rule_tac x = cs in exI, auto simp:eq_set)
|
|
1786 |
ultimately show ?thesis by auto
|
|
1787 |
qed
|
|
1788 |
moreover have "cntCS (e#s) th = cntCS s th"
|
|
1789 |
proof -
|
|
1790 |
from eq_wq and th_in and neq_hd
|
|
1791 |
have "(holdents (e # s) th) = (holdents s th)"
|
|
1792 |
apply (unfold eq_e step_depend_v[OF vtv],
|
|
1793 |
auto simp:next_th_def eq_set s_depend_def holdents_def wq_def
|
|
1794 |
Let_def cs_holding_def)
|
|
1795 |
by (insert wq_distinct[OF step_back_vt[OF vtv], of cs], auto simp:wq_def)
|
|
1796 |
thus ?thesis by (simp add:cntCS_def)
|
|
1797 |
qed
|
|
1798 |
moreover note ih eq_cnp eq_cnv eq_threads
|
|
1799 |
ultimately show ?thesis by auto
|
|
1800 |
next
|
|
1801 |
case True
|
|
1802 |
let ?rest = " (SOME q. distinct q \<and> set q = set rest)"
|
|
1803 |
let ?t = "hd ?rest"
|
|
1804 |
from True eq_wq th_in neq_th
|
|
1805 |
have "th \<in> readys (e # s)"
|
|
1806 |
apply (auto simp:eq_e readys_def s_waiting_def wq_def
|
|
1807 |
Let_def next_th_def)
|
|
1808 |
proof -
|
|
1809 |
assume eq_wq: "waiting_queue (schs s) cs = thread # rest"
|
|
1810 |
and t_in: "?t \<in> set rest"
|
|
1811 |
show "?t \<in> threads s"
|
|
1812 |
proof(rule wq_threads[OF step_back_vt[OF vtv]])
|
|
1813 |
from eq_wq and t_in
|
|
1814 |
show "?t \<in> set (wq s cs)" by (auto simp:wq_def)
|
|
1815 |
qed
|
|
1816 |
next
|
|
1817 |
fix csa
|
|
1818 |
assume eq_wq: "waiting_queue (schs s) cs = thread # rest"
|
|
1819 |
and t_in: "?t \<in> set rest"
|
|
1820 |
and neq_cs: "csa \<noteq> cs"
|
|
1821 |
and t_in': "?t \<in> set (waiting_queue (schs s) csa)"
|
|
1822 |
show "?t = hd (waiting_queue (schs s) csa)"
|
|
1823 |
proof -
|
|
1824 |
{ assume neq_hd': "?t \<noteq> hd (waiting_queue (schs s) csa)"
|
|
1825 |
from wq_distinct[OF step_back_vt[OF vtv], of cs] and
|
|
1826 |
eq_wq[folded wq_def] and t_in eq_wq
|
|
1827 |
have "?t \<noteq> thread" by auto
|
|
1828 |
with eq_wq and t_in
|
|
1829 |
have w1: "waiting s ?t cs"
|
|
1830 |
by (auto simp:s_waiting_def wq_def)
|
|
1831 |
from t_in' neq_hd'
|
|
1832 |
have w2: "waiting s ?t csa"
|
|
1833 |
by (auto simp:s_waiting_def wq_def)
|
|
1834 |
from waiting_unique[OF step_back_vt[OF vtv] w1 w2]
|
|
1835 |
and neq_cs have "False" by auto
|
|
1836 |
} thus ?thesis by auto
|
|
1837 |
qed
|
|
1838 |
qed
|
|
1839 |
moreover have "cntP s th = cntV s th + cntCS s th + 1"
|
|
1840 |
proof -
|
|
1841 |
have "th \<notin> readys s"
|
|
1842 |
proof -
|
|
1843 |
from True eq_wq neq_th th_in
|
|
1844 |
show ?thesis
|
|
1845 |
apply (unfold readys_def s_waiting_def, auto)
|
|
1846 |
by (rule_tac x = cs in exI, auto)
|
|
1847 |
qed
|
|
1848 |
moreover have "th \<in> threads s"
|
|
1849 |
proof -
|
|
1850 |
from th_in eq_wq
|
|
1851 |
have "th \<in> set (wq s cs)" by simp
|
|
1852 |
from wq_threads [OF step_back_vt[OF vtv] this]
|
|
1853 |
show ?thesis .
|
|
1854 |
qed
|
|
1855 |
ultimately show ?thesis using ih by auto
|
|
1856 |
qed
|
|
1857 |
moreover from True neq_th have "cntCS (e # s) th = 1 + cntCS s th"
|
|
1858 |
apply (unfold cntCS_def holdents_def eq_e step_depend_v[OF vtv], auto)
|
|
1859 |
proof -
|
|
1860 |
show "card {csa. (Cs csa, Th th) \<in> depend s \<or> csa = cs} =
|
|
1861 |
Suc (card {cs. (Cs cs, Th th) \<in> depend s})"
|
|
1862 |
(is "card ?A = Suc (card ?B)")
|
|
1863 |
proof -
|
|
1864 |
have "?A = insert cs ?B" by auto
|
|
1865 |
hence "card ?A = card (insert cs ?B)" by simp
|
|
1866 |
also have "\<dots> = Suc (card ?B)"
|
|
1867 |
proof(rule card_insert_disjoint)
|
|
1868 |
have "?B \<subseteq> ((\<lambda> (x, y). the_cs x) ` depend s)"
|
|
1869 |
apply (auto simp:image_def)
|
|
1870 |
by (rule_tac x = "(Cs x, Th th)" in bexI, auto)
|
|
1871 |
with finite_depend[OF step_back_vt[OF vtv]]
|
|
1872 |
show "finite {cs. (Cs cs, Th th) \<in> depend s}" by (auto intro:finite_subset)
|
|
1873 |
next
|
|
1874 |
show "cs \<notin> {cs. (Cs cs, Th th) \<in> depend s}"
|
|
1875 |
proof
|
|
1876 |
assume "cs \<in> {cs. (Cs cs, Th th) \<in> depend s}"
|
|
1877 |
hence "(Cs cs, Th th) \<in> depend s" by simp
|
|
1878 |
with True neq_th eq_wq show False
|
|
1879 |
by (auto simp:next_th_def s_depend_def cs_holding_def)
|
|
1880 |
qed
|
|
1881 |
qed
|
|
1882 |
finally show ?thesis .
|
|
1883 |
qed
|
|
1884 |
qed
|
|
1885 |
moreover note eq_cnp eq_cnv
|
|
1886 |
ultimately show ?thesis by simp
|
|
1887 |
qed
|
|
1888 |
qed
|
|
1889 |
} ultimately show ?thesis by blast
|
|
1890 |
qed
|
|
1891 |
next
|
|
1892 |
case (thread_set thread prio)
|
|
1893 |
assume eq_e: "e = Set thread prio"
|
|
1894 |
and is_runing: "thread \<in> runing s"
|
|
1895 |
show ?thesis
|
|
1896 |
proof -
|
|
1897 |
from eq_e have eq_cnp: "cntP (e#s) th = cntP s th" by (simp add:cntP_def count_def)
|
|
1898 |
from eq_e have eq_cnv: "cntV (e#s) th = cntV s th" by (simp add:cntV_def count_def)
|
|
1899 |
have eq_cncs: "cntCS (e#s) th = cntCS s th"
|
|
1900 |
unfolding cntCS_def holdents_def
|
|
1901 |
by (simp add:depend_set_unchanged eq_e)
|
|
1902 |
from eq_e have eq_readys: "readys (e#s) = readys s"
|
|
1903 |
by (simp add:readys_def cs_waiting_def s_waiting_def wq_def,
|
|
1904 |
auto simp:Let_def)
|
|
1905 |
{ assume "th \<noteq> thread"
|
|
1906 |
with eq_readys eq_e
|
|
1907 |
have "(th \<in> readys (e # s) \<or> th \<notin> threads (e # s)) =
|
|
1908 |
(th \<in> readys (s) \<or> th \<notin> threads (s))"
|
|
1909 |
by (simp add:threads.simps)
|
|
1910 |
with eq_cnp eq_cnv eq_cncs ih is_runing
|
|
1911 |
have ?thesis by simp
|
|
1912 |
} moreover {
|
|
1913 |
assume eq_th: "th = thread"
|
|
1914 |
with is_runing ih have " cntP s th = cntV s th + cntCS s th"
|
|
1915 |
by (unfold runing_def, auto)
|
|
1916 |
moreover from eq_th and eq_readys is_runing have "th \<in> readys (e#s)"
|
|
1917 |
by (simp add:runing_def)
|
|
1918 |
moreover note eq_cnp eq_cnv eq_cncs
|
|
1919 |
ultimately have ?thesis by auto
|
|
1920 |
} ultimately show ?thesis by blast
|
|
1921 |
qed
|
|
1922 |
qed
|
|
1923 |
next
|
|
1924 |
case vt_nil
|
|
1925 |
show ?case
|
|
1926 |
by (unfold cntP_def cntV_def cntCS_def,
|
|
1927 |
auto simp:count_def holdents_def s_depend_def wq_def cs_holding_def)
|
|
1928 |
qed
|
|
1929 |
qed
|
|
1930 |
|
|
1931 |
lemma not_thread_cncs:
|
|
1932 |
fixes th s
|
|
1933 |
assumes vt: "vt step s"
|
|
1934 |
and not_in: "th \<notin> threads s"
|
|
1935 |
shows "cntCS s th = 0"
|
|
1936 |
proof -
|
|
1937 |
from vt not_in show ?thesis
|
|
1938 |
proof(induct arbitrary:th)
|
|
1939 |
case (vt_cons s e th)
|
|
1940 |
assume vt: "vt step s"
|
|
1941 |
and ih: "\<And>th. th \<notin> threads s \<Longrightarrow> cntCS s th = 0"
|
|
1942 |
and stp: "step s e"
|
|
1943 |
and not_in: "th \<notin> threads (e # s)"
|
|
1944 |
from stp show ?case
|
|
1945 |
proof(cases)
|
|
1946 |
case (thread_create thread prio)
|
|
1947 |
assume eq_e: "e = Create thread prio"
|
|
1948 |
and not_in': "thread \<notin> threads s"
|
|
1949 |
have "cntCS (e # s) th = cntCS s th"
|
|
1950 |
apply (unfold eq_e cntCS_def holdents_def)
|
|
1951 |
by (simp add:depend_create_unchanged)
|
|
1952 |
moreover have "th \<notin> threads s"
|
|
1953 |
proof -
|
|
1954 |
from not_in eq_e show ?thesis by simp
|
|
1955 |
qed
|
|
1956 |
moreover note ih ultimately show ?thesis by auto
|
|
1957 |
next
|
|
1958 |
case (thread_exit thread)
|
|
1959 |
assume eq_e: "e = Exit thread"
|
|
1960 |
and nh: "holdents s thread = {}"
|
|
1961 |
have eq_cns: "cntCS (e # s) th = cntCS s th"
|
|
1962 |
apply (unfold eq_e cntCS_def holdents_def)
|
|
1963 |
by (simp add:depend_exit_unchanged)
|
|
1964 |
show ?thesis
|
|
1965 |
proof(cases "th = thread")
|
|
1966 |
case True
|
|
1967 |
have "cntCS s th = 0" by (unfold cntCS_def, auto simp:nh True)
|
|
1968 |
with eq_cns show ?thesis by simp
|
|
1969 |
next
|
|
1970 |
case False
|
|
1971 |
with not_in and eq_e
|
|
1972 |
have "th \<notin> threads s" by simp
|
|
1973 |
from ih[OF this] and eq_cns show ?thesis by simp
|
|
1974 |
qed
|
|
1975 |
next
|
|
1976 |
case (thread_P thread cs)
|
|
1977 |
assume eq_e: "e = P thread cs"
|
|
1978 |
and is_runing: "thread \<in> runing s"
|
|
1979 |
from prems have vtp: "vt step (P thread cs#s)" by auto
|
|
1980 |
have neq_th: "th \<noteq> thread"
|
|
1981 |
proof -
|
|
1982 |
from not_in eq_e have "th \<notin> threads s" by simp
|
|
1983 |
moreover from is_runing have "thread \<in> threads s"
|
|
1984 |
by (simp add:runing_def readys_def)
|
|
1985 |
ultimately show ?thesis by auto
|
|
1986 |
qed
|
|
1987 |
hence "cntCS (e # s) th = cntCS s th "
|
|
1988 |
apply (unfold cntCS_def holdents_def eq_e)
|
|
1989 |
by (unfold step_depend_p[OF vtp], auto)
|
|
1990 |
moreover have "cntCS s th = 0"
|
|
1991 |
proof(rule ih)
|
|
1992 |
from not_in eq_e show "th \<notin> threads s" by simp
|
|
1993 |
qed
|
|
1994 |
ultimately show ?thesis by simp
|
|
1995 |
next
|
|
1996 |
case (thread_V thread cs)
|
|
1997 |
assume eq_e: "e = V thread cs"
|
|
1998 |
and is_runing: "thread \<in> runing s"
|
|
1999 |
and hold: "holding s thread cs"
|
|
2000 |
have neq_th: "th \<noteq> thread"
|
|
2001 |
proof -
|
|
2002 |
from not_in eq_e have "th \<notin> threads s" by simp
|
|
2003 |
moreover from is_runing have "thread \<in> threads s"
|
|
2004 |
by (simp add:runing_def readys_def)
|
|
2005 |
ultimately show ?thesis by auto
|
|
2006 |
qed
|
|
2007 |
from prems have vtv: "vt step (V thread cs#s)" by auto
|
|
2008 |
from hold obtain rest
|
|
2009 |
where eq_wq: "wq s cs = thread # rest"
|
|
2010 |
by (case_tac "wq s cs", auto simp:s_holding_def)
|
|
2011 |
from not_in eq_e eq_wq
|
|
2012 |
have "\<not> next_th s thread cs th"
|
|
2013 |
apply (auto simp:next_th_def)
|
|
2014 |
proof -
|
|
2015 |
assume ne: "rest \<noteq> []"
|
|
2016 |
and ni: "hd (SOME q. distinct q \<and> set q = set rest) \<notin> threads s" (is "?t \<notin> threads s")
|
|
2017 |
have "?t \<in> set rest"
|
|
2018 |
proof(rule someI2)
|
|
2019 |
from wq_distinct[OF step_back_vt[OF vtv], of cs] and eq_wq
|
|
2020 |
show "distinct rest \<and> set rest = set rest" by auto
|
|
2021 |
next
|
|
2022 |
fix x assume "distinct x \<and> set x = set rest" with ne
|
|
2023 |
show "hd x \<in> set rest" by (cases x, auto)
|
|
2024 |
qed
|
|
2025 |
with eq_wq have "?t \<in> set (wq s cs)" by simp
|
|
2026 |
from wq_threads[OF step_back_vt[OF vtv], OF this] and ni
|
|
2027 |
show False by auto
|
|
2028 |
qed
|
|
2029 |
moreover note neq_th eq_wq
|
|
2030 |
ultimately have "cntCS (e # s) th = cntCS s th"
|
|
2031 |
by (unfold eq_e cntCS_def holdents_def step_depend_v[OF vtv], auto)
|
|
2032 |
moreover have "cntCS s th = 0"
|
|
2033 |
proof(rule ih)
|
|
2034 |
from not_in eq_e show "th \<notin> threads s" by simp
|
|
2035 |
qed
|
|
2036 |
ultimately show ?thesis by simp
|
|
2037 |
next
|
|
2038 |
case (thread_set thread prio)
|
|
2039 |
print_facts
|
|
2040 |
assume eq_e: "e = Set thread prio"
|
|
2041 |
and is_runing: "thread \<in> runing s"
|
|
2042 |
from not_in and eq_e have "th \<notin> threads s" by auto
|
|
2043 |
from ih [OF this] and eq_e
|
|
2044 |
show ?thesis
|
|
2045 |
apply (unfold eq_e cntCS_def holdents_def)
|
|
2046 |
by (simp add:depend_set_unchanged)
|
|
2047 |
qed
|
|
2048 |
next
|
|
2049 |
case vt_nil
|
|
2050 |
show ?case
|
|
2051 |
by (unfold cntCS_def,
|
|
2052 |
auto simp:count_def holdents_def s_depend_def wq_def cs_holding_def)
|
|
2053 |
qed
|
|
2054 |
qed
|
|
2055 |
|
|
2056 |
lemma eq_waiting: "waiting (wq (s::state)) th cs = waiting s th cs"
|
|
2057 |
by (auto simp:s_waiting_def cs_waiting_def)
|
|
2058 |
|
|
2059 |
lemma dm_depend_threads:
|
|
2060 |
fixes th s
|
|
2061 |
assumes vt: "vt step s"
|
|
2062 |
and in_dom: "(Th th) \<in> Domain (depend s)"
|
|
2063 |
shows "th \<in> threads s"
|
|
2064 |
proof -
|
|
2065 |
from in_dom obtain n where "(Th th, n) \<in> depend s" by auto
|
|
2066 |
moreover from depend_target_th[OF this] obtain cs where "n = Cs cs" by auto
|
|
2067 |
ultimately have "(Th th, Cs cs) \<in> depend s" by simp
|
|
2068 |
hence "th \<in> set (wq s cs)"
|
|
2069 |
by (unfold s_depend_def, auto simp:cs_waiting_def)
|
|
2070 |
from wq_threads [OF vt this] show ?thesis .
|
|
2071 |
qed
|
|
2072 |
|
|
2073 |
lemma cp_eq_cpreced: "cp s th = cpreced s (wq s) th"
|
|
2074 |
proof(unfold cp_def wq_def, induct s)
|
|
2075 |
case (Cons e s')
|
|
2076 |
show ?case
|
|
2077 |
by (auto simp:Let_def)
|
|
2078 |
next
|
|
2079 |
case Nil
|
|
2080 |
show ?case by (auto simp:Let_def)
|
|
2081 |
qed
|
|
2082 |
|
|
2083 |
|
|
2084 |
lemma runing_unique:
|
|
2085 |
fixes th1 th2 s
|
|
2086 |
assumes vt: "vt step s"
|
|
2087 |
and runing_1: "th1 \<in> runing s"
|
|
2088 |
and runing_2: "th2 \<in> runing s"
|
|
2089 |
shows "th1 = th2"
|
|
2090 |
proof -
|
|
2091 |
from runing_1 and runing_2 have "cp s th1 = cp s th2"
|
|
2092 |
by (unfold runing_def, simp)
|
|
2093 |
hence eq_max: "Max ((\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1)) =
|
|
2094 |
Max ((\<lambda>th. preced th s) ` ({th2} \<union> dependents (wq s) th2))"
|
|
2095 |
(is "Max (?f ` ?A) = Max (?f ` ?B)")
|
|
2096 |
by (unfold cp_eq_cpreced cpreced_def)
|
|
2097 |
obtain th1' where th1_in: "th1' \<in> ?A" and eq_f_th1: "?f th1' = Max (?f ` ?A)"
|
|
2098 |
proof -
|
|
2099 |
have h1: "finite (?f ` ?A)"
|
|
2100 |
proof -
|
|
2101 |
have "finite ?A"
|
|
2102 |
proof -
|
|
2103 |
have "finite (dependents (wq s) th1)"
|
|
2104 |
proof-
|
|
2105 |
have "finite {th'. (Th th', Th th1) \<in> (depend (wq s))\<^sup>+}"
|
|
2106 |
proof -
|
|
2107 |
let ?F = "\<lambda> (x, y). the_th x"
|
|
2108 |
have "{th'. (Th th', Th th1) \<in> (depend (wq s))\<^sup>+} \<subseteq> ?F ` ((depend (wq s))\<^sup>+)"
|
|
2109 |
apply (auto simp:image_def)
|
|
2110 |
by (rule_tac x = "(Th x, Th th1)" in bexI, auto)
|
|
2111 |
moreover have "finite \<dots>"
|
|
2112 |
proof -
|
|
2113 |
from finite_depend[OF vt] have "finite (depend s)" .
|
|
2114 |
hence "finite ((depend (wq s))\<^sup>+)"
|
|
2115 |
apply (unfold finite_trancl)
|
|
2116 |
by (auto simp: s_depend_def cs_depend_def wq_def)
|
|
2117 |
thus ?thesis by auto
|
|
2118 |
qed
|
|
2119 |
ultimately show ?thesis by (auto intro:finite_subset)
|
|
2120 |
qed
|
|
2121 |
thus ?thesis by (simp add:cs_dependents_def)
|
|
2122 |
qed
|
|
2123 |
thus ?thesis by simp
|
|
2124 |
qed
|
|
2125 |
thus ?thesis by auto
|
|
2126 |
qed
|
|
2127 |
moreover have h2: "(?f ` ?A) \<noteq> {}"
|
|
2128 |
proof -
|
|
2129 |
have "?A \<noteq> {}" by simp
|
|
2130 |
thus ?thesis by simp
|
|
2131 |
qed
|
|
2132 |
from Max_in [OF h1 h2]
|
|
2133 |
have "Max (?f ` ?A) \<in> (?f ` ?A)" .
|
|
2134 |
thus ?thesis by (auto intro:that)
|
|
2135 |
qed
|
|
2136 |
obtain th2' where th2_in: "th2' \<in> ?B" and eq_f_th2: "?f th2' = Max (?f ` ?B)"
|
|
2137 |
proof -
|
|
2138 |
have h1: "finite (?f ` ?B)"
|
|
2139 |
proof -
|
|
2140 |
have "finite ?B"
|
|
2141 |
proof -
|
|
2142 |
have "finite (dependents (wq s) th2)"
|
|
2143 |
proof-
|
|
2144 |
have "finite {th'. (Th th', Th th2) \<in> (depend (wq s))\<^sup>+}"
|
|
2145 |
proof -
|
|
2146 |
let ?F = "\<lambda> (x, y). the_th x"
|
|
2147 |
have "{th'. (Th th', Th th2) \<in> (depend (wq s))\<^sup>+} \<subseteq> ?F ` ((depend (wq s))\<^sup>+)"
|
|
2148 |
apply (auto simp:image_def)
|
|
2149 |
by (rule_tac x = "(Th x, Th th2)" in bexI, auto)
|
|
2150 |
moreover have "finite \<dots>"
|
|
2151 |
proof -
|
|
2152 |
from finite_depend[OF vt] have "finite (depend s)" .
|
|
2153 |
hence "finite ((depend (wq s))\<^sup>+)"
|
|
2154 |
apply (unfold finite_trancl)
|
|
2155 |
by (auto simp: s_depend_def cs_depend_def wq_def)
|
|
2156 |
thus ?thesis by auto
|
|
2157 |
qed
|
|
2158 |
ultimately show ?thesis by (auto intro:finite_subset)
|
|
2159 |
qed
|
|
2160 |
thus ?thesis by (simp add:cs_dependents_def)
|
|
2161 |
qed
|
|
2162 |
thus ?thesis by simp
|
|
2163 |
qed
|
|
2164 |
thus ?thesis by auto
|
|
2165 |
qed
|
|
2166 |
moreover have h2: "(?f ` ?B) \<noteq> {}"
|
|
2167 |
proof -
|
|
2168 |
have "?B \<noteq> {}" by simp
|
|
2169 |
thus ?thesis by simp
|
|
2170 |
qed
|
|
2171 |
from Max_in [OF h1 h2]
|
|
2172 |
have "Max (?f ` ?B) \<in> (?f ` ?B)" .
|
|
2173 |
thus ?thesis by (auto intro:that)
|
|
2174 |
qed
|
|
2175 |
from eq_f_th1 eq_f_th2 eq_max
|
|
2176 |
have eq_preced: "preced th1' s = preced th2' s" by auto
|
|
2177 |
hence eq_th12: "th1' = th2'"
|
|
2178 |
proof (rule preced_unique)
|
|
2179 |
from th1_in have "th1' = th1 \<or> (th1' \<in> dependents (wq s) th1)" by simp
|
|
2180 |
thus "th1' \<in> threads s"
|
|
2181 |
proof
|
|
2182 |
assume "th1' \<in> dependents (wq s) th1"
|
|
2183 |
hence "(Th th1') \<in> Domain ((depend s)^+)"
|
|
2184 |
apply (unfold cs_dependents_def cs_depend_def s_depend_def)
|
|
2185 |
by (auto simp:Domain_def)
|
|
2186 |
hence "(Th th1') \<in> Domain (depend s)" by (simp add:trancl_domain)
|
|
2187 |
from dm_depend_threads[OF vt this] show ?thesis .
|
|
2188 |
next
|
|
2189 |
assume "th1' = th1"
|
|
2190 |
with runing_1 show ?thesis
|
|
2191 |
by (unfold runing_def readys_def, auto)
|
|
2192 |
qed
|
|
2193 |
next
|
|
2194 |
from th2_in have "th2' = th2 \<or> (th2' \<in> dependents (wq s) th2)" by simp
|
|
2195 |
thus "th2' \<in> threads s"
|
|
2196 |
proof
|
|
2197 |
assume "th2' \<in> dependents (wq s) th2"
|
|
2198 |
hence "(Th th2') \<in> Domain ((depend s)^+)"
|
|
2199 |
apply (unfold cs_dependents_def cs_depend_def s_depend_def)
|
|
2200 |
by (auto simp:Domain_def)
|
|
2201 |
hence "(Th th2') \<in> Domain (depend s)" by (simp add:trancl_domain)
|
|
2202 |
from dm_depend_threads[OF vt this] show ?thesis .
|
|
2203 |
next
|
|
2204 |
assume "th2' = th2"
|
|
2205 |
with runing_2 show ?thesis
|
|
2206 |
by (unfold runing_def readys_def, auto)
|
|
2207 |
qed
|
|
2208 |
qed
|
|
2209 |
from th1_in have "th1' = th1 \<or> th1' \<in> dependents (wq s) th1" by simp
|
|
2210 |
thus ?thesis
|
|
2211 |
proof
|
|
2212 |
assume eq_th': "th1' = th1"
|
|
2213 |
from th2_in have "th2' = th2 \<or> th2' \<in> dependents (wq s) th2" by simp
|
|
2214 |
thus ?thesis
|
|
2215 |
proof
|
|
2216 |
assume "th2' = th2" thus ?thesis using eq_th' eq_th12 by simp
|
|
2217 |
next
|
|
2218 |
assume "th2' \<in> dependents (wq s) th2"
|
|
2219 |
with eq_th12 eq_th' have "th1 \<in> dependents (wq s) th2" by simp
|
|
2220 |
hence "(Th th1, Th th2) \<in> (depend s)^+"
|
|
2221 |
by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
|
|
2222 |
hence "Th th1 \<in> Domain ((depend s)^+)" using Domain_def [of "(depend s)^+"]
|
|
2223 |
by auto
|
|
2224 |
hence "Th th1 \<in> Domain (depend s)" by (simp add:trancl_domain)
|
|
2225 |
then obtain n where d: "(Th th1, n) \<in> depend s" by (auto simp:Domain_def)
|
|
2226 |
from depend_target_th [OF this]
|
|
2227 |
obtain cs' where "n = Cs cs'" by auto
|
|
2228 |
with d have "(Th th1, Cs cs') \<in> depend s" by simp
|
|
2229 |
with runing_1 have "False"
|
|
2230 |
apply (unfold runing_def readys_def s_depend_def)
|
|
2231 |
by (auto simp:eq_waiting)
|
|
2232 |
thus ?thesis by simp
|
|
2233 |
qed
|
|
2234 |
next
|
|
2235 |
assume th1'_in: "th1' \<in> dependents (wq s) th1"
|
|
2236 |
from th2_in have "th2' = th2 \<or> th2' \<in> dependents (wq s) th2" by simp
|
|
2237 |
thus ?thesis
|
|
2238 |
proof
|
|
2239 |
assume "th2' = th2"
|
|
2240 |
with th1'_in eq_th12 have "th2 \<in> dependents (wq s) th1" by simp
|
|
2241 |
hence "(Th th2, Th th1) \<in> (depend s)^+"
|
|
2242 |
by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
|
|
2243 |
hence "Th th2 \<in> Domain ((depend s)^+)" using Domain_def [of "(depend s)^+"]
|
|
2244 |
by auto
|
|
2245 |
hence "Th th2 \<in> Domain (depend s)" by (simp add:trancl_domain)
|
|
2246 |
then obtain n where d: "(Th th2, n) \<in> depend s" by (auto simp:Domain_def)
|
|
2247 |
from depend_target_th [OF this]
|
|
2248 |
obtain cs' where "n = Cs cs'" by auto
|
|
2249 |
with d have "(Th th2, Cs cs') \<in> depend s" by simp
|
|
2250 |
with runing_2 have "False"
|
|
2251 |
apply (unfold runing_def readys_def s_depend_def)
|
|
2252 |
by (auto simp:eq_waiting)
|
|
2253 |
thus ?thesis by simp
|
|
2254 |
next
|
|
2255 |
assume "th2' \<in> dependents (wq s) th2"
|
|
2256 |
with eq_th12 have "th1' \<in> dependents (wq s) th2" by simp
|
|
2257 |
hence h1: "(Th th1', Th th2) \<in> (depend s)^+"
|
|
2258 |
by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
|
|
2259 |
from th1'_in have h2: "(Th th1', Th th1) \<in> (depend s)^+"
|
|
2260 |
by (unfold cs_dependents_def s_depend_def cs_depend_def, simp)
|
|
2261 |
show ?thesis
|
|
2262 |
proof(rule dchain_unique[OF vt h1 _ h2, symmetric])
|
|
2263 |
from runing_1 show "th1 \<in> readys s" by (simp add:runing_def)
|
|
2264 |
from runing_2 show "th2 \<in> readys s" by (simp add:runing_def)
|
|
2265 |
qed
|
|
2266 |
qed
|
|
2267 |
qed
|
|
2268 |
qed
|
|
2269 |
|
|
2270 |
lemma create_pre:
|
|
2271 |
assumes stp: "step s e"
|
|
2272 |
and not_in: "th \<notin> threads s"
|
|
2273 |
and is_in: "th \<in> threads (e#s)"
|
|
2274 |
obtains prio where "e = Create th prio"
|
|
2275 |
proof -
|
|
2276 |
from assms
|
|
2277 |
show ?thesis
|
|
2278 |
proof(cases)
|
|
2279 |
case (thread_create thread prio)
|
|
2280 |
with is_in not_in have "e = Create th prio" by simp
|
|
2281 |
from that[OF this] show ?thesis .
|
|
2282 |
next
|
|
2283 |
case (thread_exit thread)
|
|
2284 |
with assms show ?thesis by (auto intro!:that)
|
|
2285 |
next
|
|
2286 |
case (thread_P thread)
|
|
2287 |
with assms show ?thesis by (auto intro!:that)
|
|
2288 |
next
|
|
2289 |
case (thread_V thread)
|
|
2290 |
with assms show ?thesis by (auto intro!:that)
|
|
2291 |
next
|
|
2292 |
case (thread_set thread)
|
|
2293 |
with assms show ?thesis by (auto intro!:that)
|
|
2294 |
qed
|
|
2295 |
qed
|
|
2296 |
|
|
2297 |
lemma length_down_to_in:
|
|
2298 |
assumes le_ij: "i \<le> j"
|
|
2299 |
and le_js: "j \<le> length s"
|
|
2300 |
shows "length (down_to j i s) = j - i"
|
|
2301 |
proof -
|
|
2302 |
have "length (down_to j i s) = length (from_to i j (rev s))"
|
|
2303 |
by (unfold down_to_def, auto)
|
|
2304 |
also have "\<dots> = j - i"
|
|
2305 |
proof(rule length_from_to_in[OF le_ij])
|
|
2306 |
from le_js show "j \<le> length (rev s)" by simp
|
|
2307 |
qed
|
|
2308 |
finally show ?thesis .
|
|
2309 |
qed
|
|
2310 |
|
|
2311 |
|
|
2312 |
lemma moment_head:
|
|
2313 |
assumes le_it: "Suc i \<le> length t"
|
|
2314 |
obtains e where "moment (Suc i) t = e#moment i t"
|
|
2315 |
proof -
|
|
2316 |
have "i \<le> Suc i" by simp
|
|
2317 |
from length_down_to_in [OF this le_it]
|
|
2318 |
have "length (down_to (Suc i) i t) = 1" by auto
|
|
2319 |
then obtain e where "down_to (Suc i) i t = [e]"
|
|
2320 |
apply (cases "(down_to (Suc i) i t)") by auto
|
|
2321 |
moreover have "down_to (Suc i) 0 t = down_to (Suc i) i t @ down_to i 0 t"
|
|
2322 |
by (rule down_to_conc[symmetric], auto)
|
|
2323 |
ultimately have eq_me: "moment (Suc i) t = e#(moment i t)"
|
|
2324 |
by (auto simp:down_to_moment)
|
|
2325 |
from that [OF this] show ?thesis .
|
|
2326 |
qed
|
|
2327 |
|
|
2328 |
lemma cnp_cnv_eq:
|
|
2329 |
fixes th s
|
|
2330 |
assumes "vt step s"
|
|
2331 |
and "th \<notin> threads s"
|
|
2332 |
shows "cntP s th = cntV s th"
|
|
2333 |
proof -
|
|
2334 |
from assms show ?thesis
|
|
2335 |
proof(induct)
|
|
2336 |
case (vt_cons s e)
|
|
2337 |
have ih: "th \<notin> threads s \<Longrightarrow> cntP s th = cntV s th" by fact
|
|
2338 |
have not_in: "th \<notin> threads (e # s)" by fact
|
|
2339 |
have "step s e" by fact
|
|
2340 |
thus ?case proof(cases)
|
|
2341 |
case (thread_create thread prio)
|
|
2342 |
assume eq_e: "e = Create thread prio"
|
|
2343 |
hence "thread \<in> threads (e#s)" by simp
|
|
2344 |
with not_in and eq_e have "th \<notin> threads s" by auto
|
|
2345 |
from ih [OF this] show ?thesis using eq_e
|
|
2346 |
by (auto simp:cntP_def cntV_def count_def)
|
|
2347 |
next
|
|
2348 |
case (thread_exit thread)
|
|
2349 |
assume eq_e: "e = Exit thread"
|
|
2350 |
and not_holding: "holdents s thread = {}"
|
|
2351 |
have vt_s: "vt step s" by fact
|
|
2352 |
from finite_holding[OF vt_s] have "finite (holdents s thread)" .
|
|
2353 |
with not_holding have "cntCS s thread = 0" by (unfold cntCS_def, auto)
|
|
2354 |
moreover have "thread \<in> readys s" using thread_exit by (auto simp:runing_def)
|
|
2355 |
moreover note cnp_cnv_cncs[OF vt_s, of thread]
|
|
2356 |
ultimately have eq_thread: "cntP s thread = cntV s thread" by auto
|
|
2357 |
show ?thesis
|
|
2358 |
proof(cases "th = thread")
|
|
2359 |
case True
|
|
2360 |
with eq_thread eq_e show ?thesis
|
|
2361 |
by (auto simp:cntP_def cntV_def count_def)
|
|
2362 |
next
|
|
2363 |
case False
|
|
2364 |
with not_in and eq_e have "th \<notin> threads s" by simp
|
|
2365 |
from ih[OF this] and eq_e show ?thesis
|
|
2366 |
by (auto simp:cntP_def cntV_def count_def)
|
|
2367 |
qed
|
|
2368 |
next
|
|
2369 |
case (thread_P thread cs)
|
|
2370 |
assume eq_e: "e = P thread cs"
|
|
2371 |
have "thread \<in> runing s" by fact
|
|
2372 |
with not_in eq_e have neq_th: "thread \<noteq> th"
|
|
2373 |
by (auto simp:runing_def readys_def)
|
|
2374 |
from not_in eq_e have "th \<notin> threads s" by simp
|
|
2375 |
from ih[OF this] and neq_th and eq_e show ?thesis
|
|
2376 |
by (auto simp:cntP_def cntV_def count_def)
|
|
2377 |
next
|
|
2378 |
case (thread_V thread cs)
|
|
2379 |
assume eq_e: "e = V thread cs"
|
|
2380 |
have "thread \<in> runing s" by fact
|
|
2381 |
with not_in eq_e have neq_th: "thread \<noteq> th"
|
|
2382 |
by (auto simp:runing_def readys_def)
|
|
2383 |
from not_in eq_e have "th \<notin> threads s" by simp
|
|
2384 |
from ih[OF this] and neq_th and eq_e show ?thesis
|
|
2385 |
by (auto simp:cntP_def cntV_def count_def)
|
|
2386 |
next
|
|
2387 |
case (thread_set thread prio)
|
|
2388 |
assume eq_e: "e = Set thread prio"
|
|
2389 |
and "thread \<in> runing s"
|
|
2390 |
hence "thread \<in> threads (e#s)"
|
|
2391 |
by (simp add:runing_def readys_def)
|
|
2392 |
with not_in and eq_e have "th \<notin> threads s" by auto
|
|
2393 |
from ih [OF this] show ?thesis using eq_e
|
|
2394 |
by (auto simp:cntP_def cntV_def count_def)
|
|
2395 |
qed
|
|
2396 |
next
|
|
2397 |
case vt_nil
|
|
2398 |
show ?case by (auto simp:cntP_def cntV_def count_def)
|
|
2399 |
qed
|
|
2400 |
qed
|
|
2401 |
|
|
2402 |
lemma eq_depend:
|
|
2403 |
"depend (wq s) = depend s"
|
|
2404 |
by (unfold cs_depend_def s_depend_def, auto)
|
|
2405 |
|
|
2406 |
lemma count_eq_dependents:
|
|
2407 |
assumes vt: "vt step s"
|
|
2408 |
and eq_pv: "cntP s th = cntV s th"
|
|
2409 |
shows "dependents (wq s) th = {}"
|
|
2410 |
proof -
|
|
2411 |
from cnp_cnv_cncs[OF vt] and eq_pv
|
|
2412 |
have "cntCS s th = 0"
|
|
2413 |
by (auto split:if_splits)
|
|
2414 |
moreover have "finite {cs. (Cs cs, Th th) \<in> depend s}"
|
|
2415 |
proof -
|
|
2416 |
from finite_holding[OF vt, of th] show ?thesis
|
|
2417 |
by (simp add:holdents_def)
|
|
2418 |
qed
|
|
2419 |
ultimately have h: "{cs. (Cs cs, Th th) \<in> depend s} = {}"
|
|
2420 |
by (unfold cntCS_def holdents_def cs_dependents_def, auto)
|
|
2421 |
show ?thesis
|
|
2422 |
proof(unfold cs_dependents_def)
|
|
2423 |
{ assume "{th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<noteq> {}"
|
|
2424 |
then obtain th' where "(Th th', Th th) \<in> (depend (wq s))\<^sup>+" by auto
|
|
2425 |
hence "False"
|
|
2426 |
proof(cases)
|
|
2427 |
assume "(Th th', Th th) \<in> depend (wq s)"
|
|
2428 |
thus "False" by (auto simp:cs_depend_def)
|
|
2429 |
next
|
|
2430 |
fix c
|
|
2431 |
assume "(c, Th th) \<in> depend (wq s)"
|
|
2432 |
with h and eq_depend show "False"
|
|
2433 |
by (cases c, auto simp:cs_depend_def)
|
|
2434 |
qed
|
|
2435 |
} thus "{th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} = {}" by auto
|
|
2436 |
qed
|
|
2437 |
qed
|
|
2438 |
|
|
2439 |
lemma dependents_threads:
|
|
2440 |
fixes s th
|
|
2441 |
assumes vt: "vt step s"
|
|
2442 |
shows "dependents (wq s) th \<subseteq> threads s"
|
|
2443 |
proof
|
|
2444 |
{ fix th th'
|
|
2445 |
assume h: "th \<in> {th'a. (Th th'a, Th th') \<in> (depend (wq s))\<^sup>+}"
|
|
2446 |
have "Th th \<in> Domain (depend s)"
|
|
2447 |
proof -
|
|
2448 |
from h obtain th' where "(Th th, Th th') \<in> (depend (wq s))\<^sup>+" by auto
|
|
2449 |
hence "(Th th) \<in> Domain ( (depend (wq s))\<^sup>+)" by (auto simp:Domain_def)
|
|
2450 |
with trancl_domain have "(Th th) \<in> Domain (depend (wq s))" by simp
|
|
2451 |
thus ?thesis using eq_depend by simp
|
|
2452 |
qed
|
|
2453 |
from dm_depend_threads[OF vt this]
|
|
2454 |
have "th \<in> threads s" .
|
|
2455 |
} note hh = this
|
|
2456 |
fix th1
|
|
2457 |
assume "th1 \<in> dependents (wq s) th"
|
|
2458 |
hence "th1 \<in> {th'a. (Th th'a, Th th) \<in> (depend (wq s))\<^sup>+}"
|
|
2459 |
by (unfold cs_dependents_def, simp)
|
|
2460 |
from hh [OF this] show "th1 \<in> threads s" .
|
|
2461 |
qed
|
|
2462 |
|
|
2463 |
lemma finite_threads:
|
|
2464 |
assumes vt: "vt step s"
|
|
2465 |
shows "finite (threads s)"
|
|
2466 |
proof -
|
|
2467 |
from vt show ?thesis
|
|
2468 |
proof(induct)
|
|
2469 |
case (vt_cons s e)
|
|
2470 |
assume vt: "vt step s"
|
|
2471 |
and step: "step s e"
|
|
2472 |
and ih: "finite (threads s)"
|
|
2473 |
from step
|
|
2474 |
show ?case
|
|
2475 |
proof(cases)
|
|
2476 |
case (thread_create thread prio)
|
|
2477 |
assume eq_e: "e = Create thread prio"
|
|
2478 |
with ih
|
|
2479 |
show ?thesis by (unfold eq_e, auto)
|
|
2480 |
next
|
|
2481 |
case (thread_exit thread)
|
|
2482 |
assume eq_e: "e = Exit thread"
|
|
2483 |
with ih show ?thesis
|
|
2484 |
by (unfold eq_e, auto)
|
|
2485 |
next
|
|
2486 |
case (thread_P thread cs)
|
|
2487 |
assume eq_e: "e = P thread cs"
|
|
2488 |
with ih show ?thesis by (unfold eq_e, auto)
|
|
2489 |
next
|
|
2490 |
case (thread_V thread cs)
|
|
2491 |
assume eq_e: "e = V thread cs"
|
|
2492 |
with ih show ?thesis by (unfold eq_e, auto)
|
|
2493 |
next
|
|
2494 |
case (thread_set thread prio)
|
|
2495 |
from vt_cons thread_set show ?thesis by simp
|
|
2496 |
qed
|
|
2497 |
next
|
|
2498 |
case vt_nil
|
|
2499 |
show ?case by (auto)
|
|
2500 |
qed
|
|
2501 |
qed
|
|
2502 |
|
|
2503 |
lemma Max_f_mono:
|
|
2504 |
assumes seq: "A \<subseteq> B"
|
|
2505 |
and np: "A \<noteq> {}"
|
|
2506 |
and fnt: "finite B"
|
|
2507 |
shows "Max (f ` A) \<le> Max (f ` B)"
|
|
2508 |
proof(rule Max_mono)
|
|
2509 |
from seq show "f ` A \<subseteq> f ` B" by auto
|
|
2510 |
next
|
|
2511 |
from np show "f ` A \<noteq> {}" by auto
|
|
2512 |
next
|
|
2513 |
from fnt and seq show "finite (f ` B)" by auto
|
|
2514 |
qed
|
|
2515 |
|
|
2516 |
lemma cp_le:
|
|
2517 |
assumes vt: "vt step s"
|
|
2518 |
and th_in: "th \<in> threads s"
|
|
2519 |
shows "cp s th \<le> Max ((\<lambda> th. (preced th s)) ` threads s)"
|
|
2520 |
proof(unfold cp_eq_cpreced cpreced_def cs_dependents_def)
|
|
2521 |
show "Max ((\<lambda>th. preced th s) ` ({th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+}))
|
|
2522 |
\<le> Max ((\<lambda>th. preced th s) ` threads s)"
|
|
2523 |
(is "Max (?f ` ?A) \<le> Max (?f ` ?B)")
|
|
2524 |
proof(rule Max_f_mono)
|
|
2525 |
show "{th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<noteq> {}" by simp
|
|
2526 |
next
|
|
2527 |
from finite_threads [OF vt]
|
|
2528 |
show "finite (threads s)" .
|
|
2529 |
next
|
|
2530 |
from th_in
|
|
2531 |
show "{th} \<union> {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<subseteq> threads s"
|
|
2532 |
apply (auto simp:Domain_def)
|
|
2533 |
apply (rule_tac dm_depend_threads[OF vt])
|
|
2534 |
apply (unfold trancl_domain [of "depend s", symmetric])
|
|
2535 |
by (unfold cs_depend_def s_depend_def, auto simp:Domain_def)
|
|
2536 |
qed
|
|
2537 |
qed
|
|
2538 |
|
|
2539 |
lemma le_cp:
|
|
2540 |
assumes vt: "vt step s"
|
|
2541 |
shows "preced th s \<le> cp s th"
|
|
2542 |
proof(unfold cp_eq_cpreced preced_def cpreced_def, simp)
|
|
2543 |
show "Prc (original_priority th s) (birthtime th s)
|
|
2544 |
\<le> Max (insert (Prc (original_priority th s) (birthtime th s))
|
|
2545 |
((\<lambda>th. Prc (original_priority th s) (birthtime th s)) ` dependents (wq s) th))"
|
|
2546 |
(is "?l \<le> Max (insert ?l ?A)")
|
|
2547 |
proof(cases "?A = {}")
|
|
2548 |
case False
|
|
2549 |
have "finite ?A" (is "finite (?f ` ?B)")
|
|
2550 |
proof -
|
|
2551 |
have "finite ?B"
|
|
2552 |
proof-
|
|
2553 |
have "finite {th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+}"
|
|
2554 |
proof -
|
|
2555 |
let ?F = "\<lambda> (x, y). the_th x"
|
|
2556 |
have "{th'. (Th th', Th th) \<in> (depend (wq s))\<^sup>+} \<subseteq> ?F ` ((depend (wq s))\<^sup>+)"
|
|
2557 |
apply (auto simp:image_def)
|
|
2558 |
by (rule_tac x = "(Th x, Th th)" in bexI, auto)
|
|
2559 |
moreover have "finite \<dots>"
|
|
2560 |
proof -
|
|
2561 |
from finite_depend[OF vt] have "finite (depend s)" .
|
|
2562 |
hence "finite ((depend (wq s))\<^sup>+)"
|
|
2563 |
apply (unfold finite_trancl)
|
|
2564 |
by (auto simp: s_depend_def cs_depend_def wq_def)
|
|
2565 |
thus ?thesis by auto
|
|
2566 |
qed
|
|
2567 |
ultimately show ?thesis by (auto intro:finite_subset)
|
|
2568 |
qed
|
|
2569 |
thus ?thesis by (simp add:cs_dependents_def)
|
|
2570 |
qed
|
|
2571 |
thus ?thesis by simp
|
|
2572 |
qed
|
|
2573 |
from Max_insert [OF this False, of ?l] show ?thesis by auto
|
|
2574 |
next
|
|
2575 |
case True
|
|
2576 |
thus ?thesis by auto
|
|
2577 |
qed
|
|
2578 |
qed
|
|
2579 |
|
|
2580 |
lemma max_cp_eq:
|
|
2581 |
assumes vt: "vt step s"
|
|
2582 |
shows "Max ((cp s) ` threads s) = Max ((\<lambda> th. (preced th s)) ` threads s)"
|
|
2583 |
(is "?l = ?r")
|
|
2584 |
proof(cases "threads s = {}")
|
|
2585 |
case True
|
|
2586 |
thus ?thesis by auto
|
|
2587 |
next
|
|
2588 |
case False
|
|
2589 |
have "?l \<in> ((cp s) ` threads s)"
|
|
2590 |
proof(rule Max_in)
|
|
2591 |
from finite_threads[OF vt]
|
|
2592 |
show "finite (cp s ` threads s)" by auto
|
|
2593 |
next
|
|
2594 |
from False show "cp s ` threads s \<noteq> {}" by auto
|
|
2595 |
qed
|
|
2596 |
then obtain th
|
|
2597 |
where th_in: "th \<in> threads s" and eq_l: "?l = cp s th" by auto
|
|
2598 |
have "\<dots> \<le> ?r" by (rule cp_le[OF vt th_in])
|
|
2599 |
moreover have "?r \<le> cp s th" (is "Max (?f ` ?A) \<le> cp s th")
|
|
2600 |
proof -
|
|
2601 |
have "?r \<in> (?f ` ?A)"
|
|
2602 |
proof(rule Max_in)
|
|
2603 |
from finite_threads[OF vt]
|
|
2604 |
show " finite ((\<lambda>th. preced th s) ` threads s)" by auto
|
|
2605 |
next
|
|
2606 |
from False show " (\<lambda>th. preced th s) ` threads s \<noteq> {}" by auto
|
|
2607 |
qed
|
|
2608 |
then obtain th' where
|
|
2609 |
th_in': "th' \<in> ?A " and eq_r: "?r = ?f th'" by auto
|
|
2610 |
from le_cp [OF vt, of th'] eq_r
|
|
2611 |
have "?r \<le> cp s th'" by auto
|
|
2612 |
moreover have "\<dots> \<le> cp s th"
|
|
2613 |
proof(fold eq_l)
|
|
2614 |
show " cp s th' \<le> Max (cp s ` threads s)"
|
|
2615 |
proof(rule Max_ge)
|
|
2616 |
from th_in' show "cp s th' \<in> cp s ` threads s"
|
|
2617 |
by auto
|
|
2618 |
next
|
|
2619 |
from finite_threads[OF vt]
|
|
2620 |
show "finite (cp s ` threads s)" by auto
|
|
2621 |
qed
|
|
2622 |
qed
|
|
2623 |
ultimately show ?thesis by auto
|
|
2624 |
qed
|
|
2625 |
ultimately show ?thesis using eq_l by auto
|
|
2626 |
qed
|
|
2627 |
|
|
2628 |
lemma max_cp_readys_threads_pre:
|
|
2629 |
assumes vt: "vt step s"
|
|
2630 |
and np: "threads s \<noteq> {}"
|
|
2631 |
shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
|
|
2632 |
proof(unfold max_cp_eq[OF vt])
|
|
2633 |
show "Max (cp s ` readys s) = Max ((\<lambda>th. preced th s) ` threads s)"
|
|
2634 |
proof -
|
|
2635 |
let ?p = "Max ((\<lambda>th. preced th s) ` threads s)"
|
|
2636 |
let ?f = "(\<lambda>th. preced th s)"
|
|
2637 |
have "?p \<in> ((\<lambda>th. preced th s) ` threads s)"
|
|
2638 |
proof(rule Max_in)
|
|
2639 |
from finite_threads[OF vt] show "finite (?f ` threads s)" by simp
|
|
2640 |
next
|
|
2641 |
from np show "?f ` threads s \<noteq> {}" by simp
|
|
2642 |
qed
|
|
2643 |
then obtain tm where tm_max: "?f tm = ?p" and tm_in: "tm \<in> threads s"
|
|
2644 |
by (auto simp:Image_def)
|
|
2645 |
from th_chain_to_ready [OF vt tm_in]
|
|
2646 |
have "tm \<in> readys s \<or> (\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (depend s)\<^sup>+)" .
|
|
2647 |
thus ?thesis
|
|
2648 |
proof
|
|
2649 |
assume "\<exists>th'. th' \<in> readys s \<and> (Th tm, Th th') \<in> (depend s)\<^sup>+ "
|
|
2650 |
then obtain th' where th'_in: "th' \<in> readys s"
|
|
2651 |
and tm_chain:"(Th tm, Th th') \<in> (depend s)\<^sup>+" by auto
|
|
2652 |
have "cp s th' = ?f tm"
|
|
2653 |
proof(subst cp_eq_cpreced, subst cpreced_def, rule Max_eqI)
|
|
2654 |
from dependents_threads[OF vt] finite_threads[OF vt]
|
|
2655 |
show "finite ((\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th'))"
|
|
2656 |
by (auto intro:finite_subset)
|
|
2657 |
next
|
|
2658 |
fix p assume p_in: "p \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')"
|
|
2659 |
from tm_max have " preced tm s = Max ((\<lambda>th. preced th s) ` threads s)" .
|
|
2660 |
moreover have "p \<le> \<dots>"
|
|
2661 |
proof(rule Max_ge)
|
|
2662 |
from finite_threads[OF vt]
|
|
2663 |
show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
|
|
2664 |
next
|
|
2665 |
from p_in and th'_in and dependents_threads[OF vt, of th']
|
|
2666 |
show "p \<in> (\<lambda>th. preced th s) ` threads s"
|
|
2667 |
by (auto simp:readys_def)
|
|
2668 |
qed
|
|
2669 |
ultimately show "p \<le> preced tm s" by auto
|
|
2670 |
next
|
|
2671 |
show "preced tm s \<in> (\<lambda>th. preced th s) ` ({th'} \<union> dependents (wq s) th')"
|
|
2672 |
proof -
|
|
2673 |
from tm_chain
|
|
2674 |
have "tm \<in> dependents (wq s) th'"
|
|
2675 |
by (unfold cs_dependents_def s_depend_def cs_depend_def, auto)
|
|
2676 |
thus ?thesis by auto
|
|
2677 |
qed
|
|
2678 |
qed
|
|
2679 |
with tm_max
|
|
2680 |
have h: "cp s th' = Max ((\<lambda>th. preced th s) ` threads s)" by simp
|
|
2681 |
show ?thesis
|
|
2682 |
proof (fold h, rule Max_eqI)
|
|
2683 |
fix q
|
|
2684 |
assume "q \<in> cp s ` readys s"
|
|
2685 |
then obtain th1 where th1_in: "th1 \<in> readys s"
|
|
2686 |
and eq_q: "q = cp s th1" by auto
|
|
2687 |
show "q \<le> cp s th'"
|
|
2688 |
apply (unfold h eq_q)
|
|
2689 |
apply (unfold cp_eq_cpreced cpreced_def)
|
|
2690 |
apply (rule Max_mono)
|
|
2691 |
proof -
|
|
2692 |
from dependents_threads [OF vt, of th1] th1_in
|
|
2693 |
show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1) \<subseteq>
|
|
2694 |
(\<lambda>th. preced th s) ` threads s"
|
|
2695 |
by (auto simp:readys_def)
|
|
2696 |
next
|
|
2697 |
show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1) \<noteq> {}" by simp
|
|
2698 |
next
|
|
2699 |
from finite_threads[OF vt]
|
|
2700 |
show " finite ((\<lambda>th. preced th s) ` threads s)" by simp
|
|
2701 |
qed
|
|
2702 |
next
|
|
2703 |
from finite_threads[OF vt]
|
|
2704 |
show "finite (cp s ` readys s)" by (auto simp:readys_def)
|
|
2705 |
next
|
|
2706 |
from th'_in
|
|
2707 |
show "cp s th' \<in> cp s ` readys s" by simp
|
|
2708 |
qed
|
|
2709 |
next
|
|
2710 |
assume tm_ready: "tm \<in> readys s"
|
|
2711 |
show ?thesis
|
|
2712 |
proof(fold tm_max)
|
|
2713 |
have cp_eq_p: "cp s tm = preced tm s"
|
|
2714 |
proof(unfold cp_eq_cpreced cpreced_def, rule Max_eqI)
|
|
2715 |
fix y
|
|
2716 |
assume hy: "y \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependents (wq s) tm)"
|
|
2717 |
show "y \<le> preced tm s"
|
|
2718 |
proof -
|
|
2719 |
{ fix y'
|
|
2720 |
assume hy' : "y' \<in> ((\<lambda>th. preced th s) ` dependents (wq s) tm)"
|
|
2721 |
have "y' \<le> preced tm s"
|
|
2722 |
proof(unfold tm_max, rule Max_ge)
|
|
2723 |
from hy' dependents_threads[OF vt, of tm]
|
|
2724 |
show "y' \<in> (\<lambda>th. preced th s) ` threads s" by auto
|
|
2725 |
next
|
|
2726 |
from finite_threads[OF vt]
|
|
2727 |
show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
|
|
2728 |
qed
|
|
2729 |
} with hy show ?thesis by auto
|
|
2730 |
qed
|
|
2731 |
next
|
|
2732 |
from dependents_threads[OF vt, of tm] finite_threads[OF vt]
|
|
2733 |
show "finite ((\<lambda>th. preced th s) ` ({tm} \<union> dependents (wq s) tm))"
|
|
2734 |
by (auto intro:finite_subset)
|
|
2735 |
next
|
|
2736 |
show "preced tm s \<in> (\<lambda>th. preced th s) ` ({tm} \<union> dependents (wq s) tm)"
|
|
2737 |
by simp
|
|
2738 |
qed
|
|
2739 |
moreover have "Max (cp s ` readys s) = cp s tm"
|
|
2740 |
proof(rule Max_eqI)
|
|
2741 |
from tm_ready show "cp s tm \<in> cp s ` readys s" by simp
|
|
2742 |
next
|
|
2743 |
from finite_threads[OF vt]
|
|
2744 |
show "finite (cp s ` readys s)" by (auto simp:readys_def)
|
|
2745 |
next
|
|
2746 |
fix y assume "y \<in> cp s ` readys s"
|
|
2747 |
then obtain th1 where th1_readys: "th1 \<in> readys s"
|
|
2748 |
and h: "y = cp s th1" by auto
|
|
2749 |
show "y \<le> cp s tm"
|
|
2750 |
apply(unfold cp_eq_p h)
|
|
2751 |
apply(unfold cp_eq_cpreced cpreced_def tm_max, rule Max_mono)
|
|
2752 |
proof -
|
|
2753 |
from finite_threads[OF vt]
|
|
2754 |
show "finite ((\<lambda>th. preced th s) ` threads s)" by simp
|
|
2755 |
next
|
|
2756 |
show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1) \<noteq> {}"
|
|
2757 |
by simp
|
|
2758 |
next
|
|
2759 |
from dependents_threads[OF vt, of th1] th1_readys
|
|
2760 |
show "(\<lambda>th. preced th s) ` ({th1} \<union> dependents (wq s) th1)
|
|
2761 |
\<subseteq> (\<lambda>th. preced th s) ` threads s"
|
|
2762 |
by (auto simp:readys_def)
|
|
2763 |
qed
|
|
2764 |
qed
|
|
2765 |
ultimately show " Max (cp s ` readys s) = preced tm s" by simp
|
|
2766 |
qed
|
|
2767 |
qed
|
|
2768 |
qed
|
|
2769 |
qed
|
|
2770 |
|
|
2771 |
lemma max_cp_readys_threads:
|
|
2772 |
assumes vt: "vt step s"
|
|
2773 |
shows "Max (cp s ` readys s) = Max (cp s ` threads s)"
|
|
2774 |
proof(cases "threads s = {}")
|
|
2775 |
case True
|
|
2776 |
thus ?thesis
|
|
2777 |
by (auto simp:readys_def)
|
|
2778 |
next
|
|
2779 |
case False
|
|
2780 |
show ?thesis by (rule max_cp_readys_threads_pre[OF vt False])
|
|
2781 |
qed
|
|
2782 |
|
|
2783 |
lemma readys_threads:
|
|
2784 |
shows "readys s \<subseteq> threads s"
|
|
2785 |
proof
|
|
2786 |
fix th
|
|
2787 |
assume "th \<in> readys s"
|
|
2788 |
thus "th \<in> threads s"
|
|
2789 |
by (unfold readys_def, auto)
|
|
2790 |
qed
|
|
2791 |
|
|
2792 |
lemma eq_holding: "holding (wq s) th cs = holding s th cs"
|
|
2793 |
apply (unfold s_holding_def cs_holding_def, simp)
|
|
2794 |
done
|
|
2795 |
|
|
2796 |
lemma f_image_eq:
|
|
2797 |
assumes h: "\<And> a. a \<in> A \<Longrightarrow> f a = g a"
|
|
2798 |
shows "f ` A = g ` A"
|
|
2799 |
proof
|
|
2800 |
show "f ` A \<subseteq> g ` A"
|
|
2801 |
by(rule image_subsetI, auto intro:h)
|
|
2802 |
next
|
|
2803 |
show "g ` A \<subseteq> f ` A"
|
|
2804 |
by(rule image_subsetI, auto intro:h[symmetric])
|
|
2805 |
qed
|
|
2806 |
|
|
2807 |
end |