Correctness.thy
changeset 66 2af87bb52fca
parent 65 633b1fc8631b
child 67 25fd656667a7
equal deleted inserted replaced
65:633b1fc8631b 66:2af87bb52fca
   598 
   598 
   599 text {* Changing counting balance to detachedness *}
   599 text {* Changing counting balance to detachedness *}
   600 lemmas runing_precond_pre_dtc = runing_precond_pre
   600 lemmas runing_precond_pre_dtc = runing_precond_pre
   601          [folded vat_t.detached_eq vat_s.detached_eq]
   601          [folded vat_t.detached_eq vat_s.detached_eq]
   602 
   602 
   603 lemma runing_precond: (* ddd *)
   603 section {* The blocking thread *}
   604   fixes th'
   604 
       
   605 text {* 
       
   606   The purpose of PIP is to ensure that the most 
       
   607   urgent thread @{term th} is not blocked unreasonably. 
       
   608   Therefore, a clear picture of the blocking thread is essential 
       
   609   to assure people that the purpose is fulfilled. 
       
   610   
       
   611   The following lemmas will give us such a picture: 
       
   612 *}
       
   613 
       
   614 (* ccc *)
       
   615 
       
   616 text {*
       
   617   The following lemma shows the blocking thread @{term th'}
       
   618   must hold some resource in the very beginning. 
       
   619 *}
       
   620 lemma runing_cntP_cntV_inv: (* ddd *)
   605   assumes th'_in: "th' \<in> threads s"
   621   assumes th'_in: "th' \<in> threads s"
   606   and neq_th': "th' \<noteq> th"
   622   and neq_th': "th' \<noteq> th"
   607   and is_runing: "th' \<in> runing (t@s)"
   623   and is_runing: "th' \<in> runing (t@s)"
   608   shows "cntP s th' > cntV s th'"
   624   shows "cntP s th' > cntV s th'"
   609   using assms
   625   using assms
   681   ultimately show ?thesis by auto
   697   ultimately show ?thesis by auto
   682 qed
   698 qed
   683 
   699 
   684 (* The foregoing two lemmas are preparation for this one, but
   700 (* The foregoing two lemmas are preparation for this one, but
   685    in long run can be combined. Maybe I am wrong.
   701    in long run can be combined. Maybe I am wrong.
       
   702    This one is useless (* XY *)
   686 *)
   703 *)
   687 lemma moment_blocked:
   704 lemma moment_blocked:
   688   assumes neq_th': "th' \<noteq> th"
   705   assumes neq_th': "th' \<noteq> th"
   689   and th'_in: "th' \<in> threads ((moment i t)@s)"
   706   and th'_in: "th' \<in> threads ((moment i t)@s)"
   690   and dtc: "detached (moment i t @ s) th'"
   707   and dtc: "detached (moment i t @ s) th'"
   699                 by (metis dtc h_i.detached_elim)
   716                 by (metis dtc h_i.detached_elim)
   700   from moment_blocked_eqpv[OF neq_th' th'_in cnt_i le_ij]
   717   from moment_blocked_eqpv[OF neq_th' th'_in cnt_i le_ij]
   701   show ?thesis by (metis h_j.detached_intro) 
   718   show ?thesis by (metis h_j.detached_intro) 
   702 qed
   719 qed
   703 
   720 
       
   721 
       
   722 text {*
       
   723   The following lemmas shows that the @{term cp}-value 
       
   724   of the blocking thread @{text th'} equals to the highest
       
   725   precedence in the whole system.
       
   726 *}
   704 lemma runing_preced_inversion:
   727 lemma runing_preced_inversion:
   705   assumes runing': "th' \<in> runing (t@s)"
   728   assumes runing': "th' \<in> runing (t@s)"
   706   shows "cp (t@s) th' = preced th s" (is "?L = ?R")
   729   shows "cp (t@s) th' = preced th s" (is "?L = ?R")
   707 proof -
   730 proof -
   708   have "?L = Max (cp (t @ s) ` readys (t @ s))" using assms
   731   have "?L = Max (cp (t @ s) ` readys (t @ s))" using assms
   710   also have "\<dots> = ?R"
   733   also have "\<dots> = ?R"
   711       by (metis th_cp_max th_cp_preced vat_t.max_cp_readys_threads) 
   734       by (metis th_cp_max th_cp_preced vat_t.max_cp_readys_threads) 
   712   finally show ?thesis .
   735   finally show ?thesis .
   713 qed
   736 qed
   714 
   737 
   715 text {*
   738 
   716   The situation when @{term "th"} is blocked is analyzed by the following lemmas.
   739 text {*
   717 *}
   740   The following lemmas shows the blocking thread @{text th'} must be live 
   718 
   741   at the very beginning, i.e. the moment (or state) @{term s}. 
   719 text {*
   742 *}
   720   The following lemmas shows the running thread @{text "th'"}, if it is different from
   743 lemma runing_threads_inv: (* ddd *)
   721   @{term th}, must be live at the very beginning. By the term {\em the very beginning},
   744   assumes runing': "th' \<in> runing (t@s)"
   722   we mean the moment where the formal investigation starts, i.e. the moment (or state)
   745   and neq_th': "th' \<noteq> th"
   723   @{term s}. 
       
   724 *}
       
   725 
       
   726 lemma runing_inversion_0:
       
   727   assumes neq_th': "th' \<noteq> th"
       
   728   and runing': "th' \<in> runing (t@s)"
       
   729   shows "th' \<in> threads s"
   746   shows "th' \<in> threads s"
   730 proof -
   747 proof -
   731     -- {* The proof is by contradiction: *}
   748     -- {* The proof is by contradiction: *}
   732     { assume otherwise: "\<not> ?thesis"
   749     { assume otherwise: "\<not> ?thesis"
   733       have "th' \<notin> runing (t @ s)"
   750       have "th' \<notin> runing (t @ s)"
   772       with `th' \<in> runing (t@s)`
   789       with `th' \<in> runing (t@s)`
   773       have False by simp
   790       have False by simp
   774     } thus ?thesis by auto
   791     } thus ?thesis by auto
   775 qed
   792 qed
   776 
   793 
   777 text {* 
   794 text {*
   778   The second lemma says, if the running thread @{text th'} is different from 
   795   The following lemma summarizes several foregoing 
   779   @{term th}, then this @{text th'} must in the possession of some resources
   796   lemmas to give an overall picture of the blocking thread @{text "th'"}:
   780   at the very beginning. 
   797 *}
   781 
   798 lemma runing_inversion:
   782   To ease the reasoning of resource possession of one particular thread, 
       
   783   we used two auxiliary functions @{term cntV} and @{term cntP}, 
       
   784   which are the counters of @{term P}-operations and 
       
   785   @{term V}-operations respectively. 
       
   786   If the number of @{term V}-operation is less than the number of 
       
   787   @{term "P"}-operations, the thread must have some unreleased resource. 
       
   788 *}
       
   789 
       
   790 lemma runing_inversion_1: (* ddd *)
       
   791   assumes neq_th': "th' \<noteq> th"
       
   792   and runing': "th' \<in> runing (t@s)"
       
   793   -- {* thread @{term "th'"} is a live on in state @{term "s"} and 
       
   794         it has some unreleased resource. *}
       
   795   shows "th' \<in> threads s \<and> cntV s th' < cntP s th'"
       
   796 proof -
       
   797   -- {* The proof is a simple composition of @{thm runing_inversion_0} and 
       
   798         @{thm runing_precond}: *}
       
   799   -- {* By applying @{thm runing_inversion_0} to assumptions,
       
   800         it can be shown that @{term th'} is live in state @{term s}: *}
       
   801   have "th' \<in> threads s"  using runing_inversion_0[OF assms(1,2)] .
       
   802   -- {* Then the thesis is derived easily by applying @{thm runing_precond}: *}
       
   803   with runing_precond [OF this neq_th' runing'] show ?thesis by simp
       
   804 qed
       
   805 
       
   806 text {* 
       
   807   The following lemma is just a rephrasing of @{thm runing_inversion_1}:
       
   808 *}
       
   809 lemma runing_inversion_2:
       
   810   assumes runing': "th' \<in> runing (t@s)"
       
   811   shows "th' = th \<or> (th' \<noteq> th \<and> th' \<in> threads s \<and> cntV s th' < cntP s th')"
       
   812 proof -
       
   813   from runing_inversion_1[OF _ runing']
       
   814   show ?thesis by auto
       
   815 qed
       
   816 
       
   817 lemma runing_inversion_3:
       
   818   assumes runing': "th' \<in> runing (t@s)"
       
   819   and neq_th: "th' \<noteq> th"
       
   820   shows "th' \<in> threads s \<and> (cntV s th' < cntP s th' \<and> cp (t@s) th' = preced th s)"
       
   821   by (metis neq_th runing' runing_inversion_2 runing_preced_inversion)
       
   822 
       
   823 lemma runing_inversion_4:
       
   824   assumes runing': "th' \<in> runing (t@s)"
   799   assumes runing': "th' \<in> runing (t@s)"
   825   and neq_th: "th' \<noteq> th"
   800   and neq_th: "th' \<noteq> th"
   826   shows "th' \<in> threads s"
   801   shows "th' \<in> threads s"
   827   and    "\<not>detached s th'"
   802   and    "\<not>detached s th'"
   828   and    "cp (t@s) th' = preced th s"
   803   and    "cp (t@s) th' = preced th s"
   829   apply (metis neq_th runing' runing_inversion_2)
   804 proof -
   830   apply (metis neq_th pv_blocked runing' runing_inversion_2 runing_precond_pre_dtc)
   805   from runing_threads_inv[OF assms]
   831   by (metis neq_th runing' runing_inversion_3)
   806   show "th' \<in> threads s" .
       
   807 next
       
   808   from runing_cntP_cntV_inv[OF runing_threads_inv[OF assms] neq_th runing']
       
   809   show "\<not>detached s th'" using vat_s.detached_eq by simp
       
   810 next
       
   811   from runing_preced_inversion[OF runing']
       
   812   show "cp (t@s) th' = preced th s" .
       
   813 qed
   832 
   814 
   833 text {* 
   815 text {* 
   834   Suppose @{term th} is not running, it is first shown that
   816   Suppose @{term th} is not running, it is first shown that
   835   there is a path in RAG leading from node @{term th} to another thread @{text "th'"} 
   817   there is a path in RAG leading from node @{term th} to another thread @{text "th'"} 
   836   in the @{term readys}-set (So @{text "th'"} is an ancestor of @{term th}}).
   818   in the @{term readys}-set (So @{text "th'"} is an ancestor of @{term th}}).