/// <summary> /// Second part of multi_level_feedback_queue /// </summary> /// <param name="size_slice"></param> void all_process_block_wakeup(double size_slice) { double size_slice2 = size_slice; while (size_slice > 0 && print_queue.Count > 0) { // int current_id = Convert.ToInt32(print_queue.Peek()); size_slice -= three_time[current_id].io_time; if (size_slice >= 0) { current_id = Convert.ToInt32(print_queue.Dequeue()); part_process_block_wakeup(current_id); } else { three_times tt1 = three_time[current_id]; tt1.io_time += size_slice; three_time[current_id] = tt1; } } while (size_slice > 0 && color_printing_queue.Count > 0) { // int current_id = Convert.ToInt32(color_printing_queue.Peek()); size_slice -= three_time[current_id].io_time; if (size_slice >= 0) { current_id = Convert.ToInt32(color_printing_queue.Dequeue()); part_process_block_wakeup(current_id); } else { three_times tt1 = three_time[current_id]; tt1.io_time += size_slice; three_time[current_id] = tt1; } } }
/// <summary> /// 2.1 /// </summary> /// <param name="current_id"></param> void part_process_block_wakeup(int current_id) { if (PCB[current_id].priority == 1) { ready_queue_1.Enqueue(current_id); } else { ready_queue_2.Enqueue(current_id); } textBox2.AppendText(System.Environment.NewLine + "====BLOCK TO READY=====" + System.Environment.NewLine); print_state_switching(); three_times tt1 = three_time[current_id]; tt1.io_time = 0; three_time[current_id] = tt1; }
/// <summary> /// One loop is one Scheduling, and it's one time_slice, /// In other part of the loop, make the process state switch. /// </summary> void multi_level_feedback_queue() { double current_time_slice; int finished_number = 0; while (finished_number < PCB.Count) { int previous_id = running_id; //jishu slice_times++; current_time_slice = process_schedule(previous_id); //new code if (three_time[running_id].cpu_time1 > 0) { double time1 = three_time[running_id].cpu_time1 - current_time_slice; if (time1 > 0) { ready_queue_2.Enqueue(running_id); pcb_contents pc = PCB[running_id]; pc.priority = 2; PCB[running_id] = pc; three_times tt1 = three_time[running_id]; tt1.cpu_time1 = time1; three_time[running_id] = tt1; // state_switching(running_id, "ready"); textBox2.AppendText(System.Environment.NewLine + "====RUNNING TO READY=====" + System.Environment.NewLine); print_state_switching(); } // Block else if (time1 <= 0 && three_time[running_id].io_time > 0) { current_time_slice += time1; // update three_times tt1 = three_time[running_id]; tt1.cpu_time1 = 0; three_time[running_id] = tt1; if (PCB[running_id].io_type == "Black and white print") { print_queue.Enqueue(running_id); } else { color_printing_queue.Enqueue(running_id); } // state_switching(running_id, "block"); textBox2.AppendText(System.Environment.NewLine + "====RUNNING TO BLOCK=====" + System.Environment.NewLine); print_state_switching(); } // finshed else { current_time_slice += time1; process_finished(); finished_number++; // state_switching(running_id, "finished"); textBox2.AppendText(System.Environment.NewLine + "====FINISHED=====" + System.Environment.NewLine); print_state_switching(); } } else { double time1 = three_time[running_id].cpu_time2 - current_time_slice; // priority -= 1 if (time1 > 0) { ready_queue_2.Enqueue(running_id); pcb_contents pc = PCB[running_id]; pc.priority = 2; PCB[running_id] = pc; three_times tt1 = three_time[running_id]; tt1.cpu_time1 = time1; three_time[running_id] = tt1; // state_switching(running_id, "ready"); textBox2.AppendText(System.Environment.NewLine + "====RUNNING TO READY=====" + System.Environment.NewLine); print_state_switching(); } // finshed else { current_time_slice += time1; process_finished(); finished_number++; // state_switching(running_id, "finshed"); textBox2.AppendText(System.Environment.NewLine + "====FINISHED=====" + System.Environment.NewLine); print_state_switching(); } } // Run the IO all_process_block_wakeup(current_time_slice); } // Process revocation process_delete(); }