round robin调度算法存在死循环

Round robin scheduling algorithm has infinite loop

我正在编写轮循算法 CPU 调度并且我使用矢量作为就绪队列。

但是当我 运行 代码时 i = *(vector.begin()) 的初始值应该为零,下一次 i 根据代码有另一个值,就像我做的 vector.push_back(0)但是当我使用调试语句时,它显示 i = 5 和无限次的值。因此,我不能将等待时间作为输出。

这是输出的代码和屏幕截图:-

代码如下:

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int a[5],w[5],b[5],c[5],x[5],tat[5],i,j,complete=0,t=0,q,y=0; //a[] is arrival time b[] is burst time w[] waitingtime q=time slice c[] is completion time
    vector<int> v;     // using this vector as a ready queue which takes indices of processes
    v.push_back(0);
    cout<<"enter the value of quanta";
    cin>>q;
    cout<<"enter values of arrival time";
    for(i=0;i<5;i++)
    {
        cin>>a[i];
    }
    cout<<"enter values of burst time";
    for(i=0;i<5;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<5;i++)
    x[i]=b[i];    //burst time keeps on changing acc to time slice so store initial burst times in array x

    while(complete!=5)     //complete denotes number of processes
    {
            i == *(v.begin());     //first process should be p0 i am considering it to give arrival time = 0
            cout<<i<<endl;
            if(a[i]<=t && b[i]>0)
            {
                for(j=1;j<=q;j++)
                {
                    b[i]--;
                    t++;      //whats the current time since cpu is running

                    if(b[i]==0)           //if just 1sec of bt of a process is left so it will come out of loop after being reduced by 1
                    break;
                }
                for(j=i+1;j<5;j++)          //to check which processes have arrived and push them in ready queue
                {
                    if(a[j]<=t && a[j]>y)
                       {  v.push_back(j);
                            y=a[j];
                       }
                }
                if(b[i] == 0)
                {
                    complete++;
                    c[i] = t;
                    w[i] = c[i] - a[i] - x[i];
                    tat[i] = c[i] - a[i];
                    v.erase(v.begin());         //remove the index of this process as it is no longer required
                }
                else                         // put the process to the last of ready queue if not completed
                {
                    v.push_back(i);
                    v.erase(v.begin());
                }
            }
        }

for(i=0;i<5;i++)
cout<<w[i]<<endl;  //display waiting times

}

这不起作用:

i == *(v.begin());

你是比较i,不是设置。将其替换为:

i = *(v.begin());