freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

課程設(shè)計(jì)-模擬銀行家算法避免死鎖-文庫(kù)吧

2024-12-29 18:59 本頁(yè)面


【正文】 數(shù)目 cout各進(jìn)程資源最大需求(Max),按照mxn矩陣輸入:\n。 for(i=0。im。i++) { coutPi:。 for(j=0。jn。j++) { cinMAX[i][j]。 if(j==n) cout資源種類數(shù)匹配出現(xiàn)錯(cuò)誤!。//當(dāng)資源配置的種類數(shù)大于預(yù)先輸入的數(shù)值時(shí),出錯(cuò) } } cout各進(jìn)程當(dāng)前獲得資源(Allocation),按照mxn矩陣輸入endl。 for(i=0。im。i++) { coutPi:。 for(j=0。jn。j++) { cinAllocation[i][j]。 if(j==n) cout資源種類數(shù)匹配出現(xiàn)錯(cuò)誤!。//當(dāng)資源配置的種類數(shù)大于預(yù)先輸入的數(shù)值時(shí),出錯(cuò) Need[i][j]=MAX[i][j]Allocation[i][j]。//需求數(shù)等于最大需求減去已經(jīng)分配數(shù) } } cout系統(tǒng)可用資源(Available):endl。 for(j=0。jn。j++) { cinAvailable[j]。//輸入各種資源的可利用數(shù) } cout當(dāng)前時(shí)刻的進(jìn)程分配情況如圖:\n。 cout進(jìn)程號(hào)MAXAllocationNeedAvailable\n。//顯示各進(jìn)程的資源情況 for(i=0。im。i++) { coutPi: 。 for(j=0。jn。j++) cout MAX[i][j]。 for(j=0。jn。j++) cout Allocation[i][j]。 cout 。 for(j=0。jn。j++) cout Need[i][j]。 for(j=0。jn。j++) cout Available[j]。 coutendl。//回車換行 }}//*****************銀行家算法,為進(jìn)程分配資源***********//void banker() { int i,j。 int choice。 while(1) { coutendl。 cout輸入要進(jìn)行的操作(1:分配資源 2:離開(kāi)) :。 //用戶選擇 cinchoice。 if(choice==1) //分配資源 { cout從P0到Pm1之間選擇要分配資源的進(jìn)程號(hào):\n。 cini。 if(i=m) { cout無(wú)此進(jìn)程號(hào)!請(qǐng)重新輸入:\n。 cini。//重新輸入進(jìn)程號(hào) } cout請(qǐng)輸入進(jìn)程申請(qǐng)的資源(Request):endl。 for(j=0。jn。j++) cinRequest[i][j]。 //**********銀行家算法進(jìn)行檢查*************// for(j=0。jn。j++) { if(Request[i][j]Need[i][j]) { cout申請(qǐng)的資源大于它需要的資源數(shù),請(qǐng)重新輸入!\n。//資源申請(qǐng)不合理 continue。 } if(Request[i][j]Available[j]) { //資源申請(qǐng)數(shù)目大于可利用數(shù),無(wú)法分配,得等待 cout當(dāng)前系統(tǒng)可用資源不夠,請(qǐng)等待!endl。 continue。 } } for(j=0。jn。j++)//資源申請(qǐng)得到允許時(shí),變換各個(gè)資源數(shù) { Available[j]=Available[j]Request[i][j]。 //可用資源減少 Allocation[i][j]=Allocation[i][j]+Request[i][j]。//所得資源增加 Need[i][j]=Need[i][j]Request[i][j]。 //仍需資源減少 } if(safealg()0)//安全性算法的返回值 { cout分配不成功,請(qǐng)等待!。 for (j=0。jn。j++) //把資源恢復(fù)成分配之前的狀態(tài) { Available[j]=Available[j]+Request[i][j]。 Allocation[i][j]=Allocation[i][j]Request[i][j]。 Need[i][j]=Need[i][j]+Request[i][j]。 } for(i=0。im。i++) { Finish[i]=False。//沒(méi)有足夠的資源分配給該進(jìn)程 } }//if(safealg()0) else { cout同意分配請(qǐng)求!endl。 for(j=0。jn。j++) Work[j]=Available[j]。 cout進(jìn)程號(hào)WorkNeedAllocationWork+Allocation Finishendl。 for(i=0。im。i++)//按模擬分配序列進(jìn)行分配 { cout進(jìn)程PSequence[i]: 。 for(j=0。jn。j++) coutWork[j] 。 cout 。 for(j=0。jn。j++) coutNeed[Sequence[i]][j] 。 cout 。 for(j=0。jn。j++) coutAllocation[Sequence[i]][j] 。 cout 。 for(j=0。jn。j++) coutAllocation[Sequence[i]][j]+Work[j] 。 cout 。 coutFinish[Sequence[i]] 。//完成該進(jìn)程 for(j=0。jn。j++) Work[j]=Allocation[Sequence[i]][j]+Work[j]。//回收該進(jìn)程所分配的資源 coutendl。 } }//if(safealg()=0) }//if(choice=1) else if(choice==2) //離開(kāi)———— break。 else cout請(qǐng)輸入1或2!。//只認(rèn)可1或2 }//while(1)}//*********安全性算法 ************//int safealg() { int i,j,k,l=0。 //int Work[MAXn]。 //工作組 //記錄序列 for(i=0。
點(diǎn)擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計(jì)相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1