我试图得到一个循环调度程序正常工作,不幸的是,尽管流血的眼泪已经溢出,它似乎仍然在我的代码中的某处出错。这里是我的功能:我需要循环法工作,但它不能正常工作
//function that processes the head of the CPU queue (RR version)
int process2 (NodePtr *headcpu, NodePtr *tailcpu, int *count, int timeslice) {
NodePtr temp2;
NodePtr temp3;
(*headcpu)->cpu_time = (*headcpu)->cpu_time - timeslice;
(*count) = (*count) + timeslice;
//if statement starts
if ((*headcpu)->cpu_time <= 0){
temp3 = dequeue_cpu(headcpu, tailcpu);
print_result (temp3, count);//call to print_result function
}//if statement ends
//else statement starts
else {
temp2 = *headcpu;
*headcpu = (*headcpu)->next;
(*tailcpu)->next = temp2;
*tailcpu = temp2;
(*tailcpu)->next = NULL;
}//else statement ends
return 0;//successful termination
}//end process2 function
这是我的输出:
3788 230 31
5001 401 39
5002 402 41
7979 461 63
7919 461 65
1008 72 75
3784 230 87
5000 400 97
7999 456 111
7909 458 115
7989 460 117
7929 462 119
Program received signal SIGSEGV, Segmentation fault.
此输出已使用36样本长的测试文件产生,正如你所看到的,只有几个值似乎是印刷不正确。我得到了段错误。
有人能找出问题的根源吗?
你好,欢迎来到SO。请记住,我们不会在此请求调试代码。启动您的调试器并将问题隔离到一行。另外,请确保您访问[本页](http://stackoverflow.com/help/how-to-ask)以查看如何针对SO提出问题。 –
我做到了:显然,它存在(* headcpu) - > cpu_time =(* headcpu) - > cpu_time - 时间片的问题。我不知道为什么...... – Michformer
请不要养成像'// if statement starts'和'//调用print_result函数'这样的注释的习惯。 –