private void btnStop_Click(object sender, EventArgs e) { cbShowMessages.Enabled = true; pnlMemory.Enabled = true; gbResQu1.Enabled = false; gbResQu2.Enabled = false; gbResQu3.Enabled = false; gbRes1.Enabled = false; gbRes2.Enabled = false; gbRes3.Enabled = false; pnlParameters.Enabled = true; btnNext.Enabled = false; btnStop.Enabled = false; btnStart.Enabled = true; lbRes1.Items.Clear(); lbRes2.Items.Clear(); lbRes3.Items.Clear(); lbResQu1.Items.Clear(); lbResQu2.Items.Clear(); lbResQu3.Items.Clear(); lbMemory.Items.Clear(); lbCpu.Items.Clear(); lbQueue.Items.Clear(); lbStats.Items.Clear(); cpu = null; cpSch = null; st = null; timer = null; queue = null; resSh = null; memSh = null; }
public void CreateProcess(int takt, PriorityQueue <Process> que, MemoryScheduler memSh) { int a = Form1.rnd.Next(0, 100) + 1; int b = (int)(intensivity * 100); if (a <= b) { EvNewProc(); int prdiap = Form1.rnd.Next(prDiapason) + 1; int memory = Form1.rnd.Next(1, memInterval + 1); int inter = Form1.rnd.Next(interval) + 1; Process pr = new Process(takt, ++numOfProcess, prdiap, inter, memory); if (memSh.LoadNewProcess(pr)) { que.Add(pr, pr.GetPriority()); EvNewLength(que.GetLength()); } else { if (showmessages) { MessageBox.Show("Процесс не поступил в очередь из-за нехватки памяти."); } EvDenied(); } } }
private void btnStart_Click(object sender, EventArgs e) { cbShowMessages.Enabled = false; pnlMemory.Enabled = false; pnlParameters.Enabled = false; btnNext.Enabled = true; btnStop.Enabled = true; btnStart.Enabled = false; rnd = new Random(); ResCount = Convert.ToInt32(numCountOfRes.Value); cpu = new Cpu(Convert.ToInt32(numQuant.Value)); timer = new Timer(); queue = new PriorityQueue <Process>(); cpSch = new CpuScheduler(Convert.ToDouble(numIntensivity.Value), Convert.ToInt32(numInterval.Value), Convert.ToInt32(numPrDiapason.Value), ResCount, Convert.ToInt32(numBitSize.Value), cbShowMessages.Checked); st = new Statistics(); resSh = new ResourceScheduler[ResCount]; memSh = new MemoryScheduler(Convert.ToInt32(numLayers.Value)); DisplayStats(); DisplayMemory(); for (int i = 0; i <= ResCount; i++) { if (i != ResCount) { resSh[i] = new ResourceScheduler(Convert.ToInt32(numInterval.Value)); resSh[i].EvEndResource += new ResourceScheduler.Delegate1(st.HndFinishRes); } switch (i) { case 1: gbRes1.Enabled = true; gbResQu1.Enabled = true; break; case 2: gbRes2.Enabled = true; gbResQu2.Enabled = true; break; case 3: gbRes3.Enabled = true; gbResQu3.Enabled = true; break; } } cpSch.EvNewProc += new CpuScheduler.Delegate1(st.HndNewProc); cpSch.EvNewLength += new CpuScheduler.Delegate2(st.HndNewLengthOfQueue); cpSch.EvProcIsFree += new CpuScheduler.Delegate1(st.HndProcIsFree); cpSch.EvFinishedProc += new CpuScheduler.Delegate3(st.HndFinishProc); cpSch.EvDenied += new CpuScheduler.Delegate1(st.HndDeniedProcess); cpSch.EvLeftProc += new CpuScheduler.Delegate1(st.HndLeftProcess); //cpSch.CreateProcess(timer.NumOfTakt, queue); //DisplayQueue(); }
public void ManipulateCpu(Cpu cpu, PriorityQueue <Process> que, ResourceScheduler[] resSh, MemoryScheduler memSh) { if (cpu.Free) { EvProcIsFree(); } if (!cpu.Free) { if (cpu.GetActiveProcess().CheckBurstTime()) { Process pr = cpu.GetActiveProcess(); EvFinishedProc(pr); int a = Form1.rnd.Next(0, numOfRes + 1); if (a == 0) { EvLeftProc(); if (showmessages) { MessageBox.Show("Процесс " + pr.Name + " завершен."); } memSh.UnloadProcess(pr); } else { if (showmessages) { MessageBox.Show("Процесс " + pr.Name + " переходит в очередь к ресурсу " + a.ToString()); } resSh[a - 1].AddNewProcess(pr); } cpu.FinishActiveProcess(); } else if (cpu.CheckQuantTime()) { Process pr = que.GetFirst(); que.DeleteFirst(); cpu.GetActiveProcess().ReducePriorityToMin(); que.AddToEnd(cpu.GetActiveProcess()); cpu.LoadNewProcess(pr); } } if (!que.IsEmpty() && !cpu.Free && que.GetFirst().GetPriority() > cpu.GetActiveProcess().GetPriority()) { Process pr = que.GetFirst(); que.DeleteFirst(); que.Add(cpu.GetActiveProcess(), cpu.GetActiveProcess().GetPriority()); cpu.LoadNewProcess(pr); } if (cpu.Free && !que.IsEmpty()) { cpu.LoadNewProcess(que.GetFirst()); que.DeleteFirst(); } }