bool CheckNewDemand(string name, Resourse demand2, Resourse Available2, List <Process> processList2) { List <Process> processList = new List <Process>(); processList2.ForEach(i => processList.Add(i.Clone())); //printPro(processList,available); Resourse Available = Available2.Clone(); Resourse demand = demand2.Clone(); //cout << "进入检查状态" << endl; for (int i = 0; i < processList.Count; i++) { if (processList[i].name != name) { continue; } if (!processList[i].Demand(ref Available, demand)) //Demand 有问题 { Console.WriteLine("错误出口1"); return(false); } else { //printPro(processList, Available); List <bool> map = new List <bool>(new bool[] { false, false, false, false, false }); //map[i] = true; //cout << "进入复查状态" << endl; return(CheckStatus(Available, processList, ref map)); } } Console.WriteLine("错误出口2"); return(false); }
public Process(string name, int a, int b, int c) { this.name = name; Max.A = a; Max.B = b; Max.C = c; Need = Max.Clone(); }
bool CheckStatus(Resourse Available2, List <Process> processList2, ref List <bool> map) { List <Process> processList = new List <Process>(); processList2.ForEach(i => processList.Add(i.Clone())); Resourse Available = Available2.Clone(); //cout << "复查被调用"<<endl; //Console.WriteLine("map状态:" + map[0] + map[1] + map[2] + map[3] + map[4]); int count = 0; foreach (var each in map) { if (each == false) { break; } count++; } if (count == 5) { return(true); } for (int i = 0; i < processList.Count; i++) { if (map[i] == true) { continue; } if (Functions.AsB(processList[i].Need, Available)) { if (processList[i].Demand(ref Available, processList[i].Need)) { map[i] = true; Functions.AddTo(ref Available, processList[i].Max); //这一步应当还原了available if (CheckStatus(Available, processList, ref map)) { return(true); } } } } Console.WriteLine("错误出口3"); return(false); }
bool CheckNewDemandT(string name, Resourse demand2, Resourse Available2, List <Process> processList2) { List <Process> processList = new List <Process>(); processList2.ForEach(i => processList.Add(i.Clone())); //printPro(processList,available); Resourse Available = Available2.Clone(); Resourse demand = demand2.Clone(); //遍历所有进程 for (int i = 0; i < processList.Count; i++) { if (processList[i].name != name) { continue; } StrInfoTransfEvent("正在预分配中"); DrawInfoTransfEvent(i, demand, processList[i].Allocation, processList[i].Max, this.available, 0); if (!processList[i].Demand(ref Available, demand)) //找到了发出申请的进程 { StrInfoTransfEvent("超出需要"); WarnInfoTransfEvent(i, "数量错误,超出需要"); return(false); } else { //printPro(processList, Available); StrInfoTransfEvent("初步检测通过,开始进行预分配安全性检测"); Thread.Sleep(500); List <bool> map = new List <bool>(new bool[] { false, false, false, false, false }); //map[i] = true; //cout << "进入复查状态" << endl; return(CheckStatusT(Available, processList, ref map)); } } Console.WriteLine("错误出口2"); return(false); }
public Process(string name, Resourse max) { this.name = name; Max = max; Need = Max.Clone(); }
bool CheckStatusT(Resourse Available2, List <Process> processList2, ref List <bool> map) { List <Process> processList = new List <Process>(); processList2.ForEach(i => processList.Add(i.Clone())); Resourse Available = Available2.Clone(); //cout << "复查被调用"<<endl; //Console.WriteLine("map状态:" + map[0] + map[1] + map[2] + map[3] + map[4]); int count = 0; for (int i = 0; i < map.Count; i++) { if (map[i] == true) { count++; } } //drawAll(map); if (count == 5) { StrInfoTransfEvent("所有的进程所需资源均被满足"); return(true); } for (int i = 0; i < processList.Count; i++) { if (map[i] == true) { continue; } DrawInfoTransfEvent(i, Available, processList[i].Allocation, processList[i].Max, this.available, 1); //listBox.Items.Add("到达节点1"); if (Functions.AsB(processList[i].Need, Available)) //这个地方好像有点重复? { if (processList[i].Demand(ref Available, processList[i].Need)) { map[i] = true; StrInfoTransfEvent("P" + (i) + "判定成功,释放资源"); //drawFlag(pictureBoxes[i], map[i]); FlagChangeEvent(i, map[i]); Functions.AddTo(ref Available, processList[i].Max); LabelChangeEvent(Available); Thread.Sleep(1000); if (CheckStatusT(Available, processList, ref map)) { return(true); } } else { WarnInfoTransfEvent(i, "此进程暂时无法完全分配"); StrInfoTransfEvent("P" + (i) + "判定失败,继续尝试"); Thread.Sleep(1000); WithDrawTransferEvent(processList[i], map, Available, i); //drawAll(map); //drawFlag(pictureBoxes[i], map[i]); Thread.Sleep(500); } } else { WarnInfoTransfEvent(i, "此进程暂时无法完全分配"); StrInfoTransfEvent("P" + (i) + "判定失败,继续尝试"); Thread.Sleep(1000); WithDrawTransferEvent(processList[i], map, Available, i); //drawAll(map); //drawFlag(pictureBoxes[i], map[i]); Thread.Sleep(500); } } return(false); }