【正文】
:\n,)。 printf(請(qǐng)初始化一組進(jìn)程 ,進(jìn)程編號(hào)從 P0 開(kāi)始,輸入 1 結(jié)束輸入 :\n)。 } } void Init_process(process **head,int m,int* count) { int i,j=0。 while(lastnext!=NULL) { last=lastnext。 if(NULL==*head) { *head=p。node,sizeof(process))。 process* last=NULL。 }process。 int Need[M]。 int Max[M]。在此向幫助和指導(dǎo)過(guò)我的各位老師表示最 真誠(chéng) 的感謝! 此外,還要 感謝我的同學(xué)和朋友,在我寫論文的過(guò)程中給予我很多素材,還在論文的撰寫和排版 的 過(guò)程中提供熱情的幫助。尤其要感謝我的論文指導(dǎo)老師 —— 陜粉麗 老師,她對(duì)我進(jìn)行了無(wú)私的指導(dǎo)和幫助,不厭其煩的幫助進(jìn)行論文的修改和改進(jìn)。 avoid deadlock。 參考文獻(xiàn) [1] 嚴(yán)蔚敏 ,吳偉民 .數(shù)據(jù)結(jié)構(gòu) (C 語(yǔ)言版 )[M].北京 :清華大學(xué)出社 ,2020. [2] 湯小丹 ,梁紅兵 ,哲鳳屏 等 .計(jì)算機(jī)操作系統(tǒng) (第三版 )[M].西安 :西安電子科技大學(xué)出版社 ,2020. [3] 譚浩強(qiáng) .C 語(yǔ)言程序設(shè)計(jì) [M].北京 :清華大學(xué)出版社 ,2020. [4] 于帆 ,趙妮 .程序設(shè)計(jì)基礎(chǔ) [M].北京 :清華大學(xué)出版社 ,2020. [5] 羅宇 .操作系統(tǒng)課程 [M].北京 :設(shè)計(jì)機(jī)械工業(yè)出版社 ,2020. [6] 黃水松 ,黃干平 ,曾平 .計(jì)算機(jī)操作系統(tǒng) [M].武漢 :武漢大學(xué)出版社 ,2020. [7] 鞠時(shí)光 .操作 系統(tǒng)原理 [M].武漢 :武漢理工大學(xué)出版社 ,2020. [8] 何炎祥 ,熊前興 .操作系統(tǒng)原理 [M].武漢 :華中科技大學(xué)出版社 ,2020. [9] 張麗芬 ,劉美華 .操作系統(tǒng)原理教程 [M].北京 :電子工業(yè)出版社 ,2020. [10] 陳火 .數(shù)據(jù)結(jié)構(gòu)與算法 [M].廣東 :中山大學(xué)出版社 ,2020. [11] 鄭扣根 .操作系統(tǒng)概念 (第七版 )[M].北京 :高等教育出版社 ,1992. [12] 趙莉 ,楊國(guó)梁 ,孫喁喁 ,徐飛 .Java 程序設(shè)計(jì)教程 [M].西安 :西安科技大學(xué)出版社 ,2020. [13] 陳向群 ,向勇 ,王雷 .Windows 操作系統(tǒng)原理 (第二版 )[M].北京 :北京機(jī)械工業(yè)出版社 ,2020. 長(zhǎng)治學(xué)院學(xué)士學(xué)位論文(設(shè)計(jì)) 13 Bankers Algorithm To Avoid Deadlock Research and Implementation Major:Computer Science and technology Name: Wang Zidan Student ID: 09407227 Supervisor:Shan Fenli Abstract:Bankers algorithm what Dijkstra put forward is the most representative of the algorithm to avoid deadlock, this algorithm can be used for the banking system because of its cash loans. Bankers algorithm is advancing in the premise of ensuring the system security. The first is that security check to process requests, to determine the allocation of resources or not, so as to ensure the safety of the system, to avoid deadlock. This paper on the understanding and analysis of the essential meaning of bankers algorithm as well as the state of the core idea, the algorithm is implemented in the overall design, including the module design of algorithm, and the algorithm of each module through a flow chart, block coding, and testing, the final program in the test, the design ideas on strictly according to the thought of software engineering implementation, to ensure that the design and implementation of feasible, credible. Keywords: bankers algorithm。但通過(guò)查閱書本,對(duì)算法細(xì)節(jié)重新建立正確的認(rèn)識(shí)后,再通過(guò)單步調(diào)試后,最終解決。 在程序測(cè)試中出現(xiàn)了很多問(wèn)題。之后,確定自己設(shè)計(jì)的算法分四大模塊。 銀行家算法避免死鎖的研究與實(shí)現(xiàn) 12 6 結(jié)論 銀行家算法避免死鎖的研究與實(shí)現(xiàn)作為我的畢業(yè)設(shè)計(jì)。 ( 4) 00: Request(0,2,0) 結(jié)果: 試分配后,系統(tǒng)不安全,試分配作廢。 ( 2) 01: Request(2,0,2) 結(jié)果: 系統(tǒng)不能滿足。 長(zhǎng)治學(xué)院學(xué)士學(xué)位論文(設(shè)計(jì)) 11 圖 12 試分配后輸出一個(gè)安全性序列 圖 13 試分配后不安全狀態(tài)的資源恢復(fù) 集成測(cè)試 各模塊測(cè)試通過(guò)后,集成在一起測(cè)試,系統(tǒng)初始資源和模塊測(cè)試時(shí)保持一致,以下是測(cè)試用例以及結(jié)果, 基本包括了該算法的所有情況。 圖 10 安全模塊 Safety_Algorithm 的調(diào)試的安全狀態(tài) 圖 11 安全模塊 Safety_Algorithm 的 調(diào)試的不安全狀態(tài) ?試分配后的安全算法,結(jié)果如果輸出一個(gè)安全性序列,并且經(jīng)過(guò)人工檢查該安全性序列,確實(shí)有效,則該模塊正確,如圖 12所示;否則,之前的試分配作廢,恢復(fù)試分配前的資源狀態(tài)。 (3)安全模塊 Safety_Algorithm 的調(diào)試 ?試分配前的安全算法,結(jié)果如果輸出一個(gè)安全性序列,并且經(jīng)過(guò)人工檢查該安全性序列,確實(shí)有效,則該模塊正確 ,如圖 10 所示;如果系統(tǒng)不安全,打印出相關(guān)信息,返回上一層。 (2)試分配模塊 Attempt_Allocation 的測(cè)試 圖 9 試分配模塊 Attempt_Allocation 的測(cè)試 試分配模塊,主要是在系統(tǒng)進(jìn)入第一次安全檢查后,對(duì)系統(tǒng)資源的一次嘗試性分配,試分配完成后,相關(guān)的數(shù)據(jù)結(jié)構(gòu)被修改。起初效果不理想,經(jīng)過(guò)一些調(diào)整后,顯示才比較理想。 開(kāi)始 Int i。 Retumn p。 Work[i]=avail[i]。 Finish[i]=pnum。 Y N Y N 開(kāi)始 結(jié)束 初始化 work, finish。 (4)對(duì)試分配后的系統(tǒng),進(jìn)行安全性檢查的程序流程圖 和圖 5 大致一樣,唯一一點(diǎn)在于當(dāng)找不到安全序列時(shí),將本次試分配作廢,恢復(fù)該次 試分配之前的數(shù)據(jù)結(jié)構(gòu)。如果為空,則輸出無(wú)此進(jìn)程,然后,輸入請(qǐng)求向量,檢查合法性,進(jìn)行試分配。 =j++。如圖 5 所示。然后,判斷異常情況,利用 Reasonable 函數(shù)找到當(dāng)前可執(zhí)行的進(jìn)程。如圖 4 所示。否則之前的試分配作廢,恢復(fù)試分配之前的數(shù)據(jù)結(jié)構(gòu),輸出相關(guān)提示信息,接收下一個(gè)進(jìn)程請(qǐng)求。 數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì) typedef struct my_process { int num; int Max[M]; int Allocation[M]; int Need[M]; struct my_process* next; }process; int Available[M]={0}; int Request[M]={0}; int Record_work[N][M]={0}; int Safety[N]={0}; 算法整體設(shè)計(jì)與調(diào)用 主函數(shù) void main() 主要分四大塊: ( 1)首先需要初始化 Init_process( process **head, int m, int* count), 存儲(chǔ)系統(tǒng)當(dāng)前狀態(tài)信息; ( 2)調(diào)用安全算法 Safety_Algorithm, 檢測(cè)當(dāng)前系統(tǒng)安全狀態(tài), 若安全則進(jìn)行下一步,否則打印相關(guān)信息,程序退出; ( 3)調(diào)用試分配函數(shù) Attempt_Allocation, 進(jìn)行試分配,若試分配成功,修改