如何计算等待Round Robin程序的时间?

时间:2015-11-12 18:16:12

标签: c++ round-robin

我第二次发布这个问题(因为没有人第一次帮助我)。所以,我需要你的Round Robin计划的帮助。当我想为每个过程计算等待时间时,我感到困惑,我不知道该怎么做,我不知道如何计算等待时间。我尝试使用不同的逻辑,但每次都失败了。

我需要你的帮助来计算等待时间

这是我的源代码。

#include<iostream>
using namespace std;

int main()
{
int BT[10], TQ, start=0, stop=0, counter=0, check=0;

cout << " Enter Time Qunatem : "; cin >> TQ;
cout << "\n How many Processes do you want? (10 is Maximum) " ; cin >> counter;

cout << "\n\n Enter Burst Time for each Process : " << endl;

for(int i = 0; i < counter; i++ )
{ cout << " P" << i+1 << " = " ; cin >> BT[i]; }

cout << "\n\n";


for( int i = 0; i < counter; i++ )
{
    if(BT[i] > 0)
    {

        if( TQ <= BT[i] )
        {

            cout << " P" << i+1 << " = ";
            BT[i] = BT[i] - TQ;
            start = stop;
            stop = stop + TQ;

            cout << BT[i] << " | Starts at : " << start << " | Stops at : " << stop << endl;


        }

        else if( TQ > BT[i] )
        {
            cout << " P" << i+1 << " = ";
            start = stop;
            stop = stop + BT[i];

            cout << BT[i] << " | Starts at : " << start << " | Stops at : " << stop << endl;

            BT[i]=0;

        }

    }


    if (i == counter-1)
    {
            for( int j = 0; j < counter; j++ )
            {
                check=check+BT[j]; 

                if (j == counter-1)
                {
                    if (check <= 0)
                    { cout << " ARRAY IS EMPTY\n"; break; }
                    else
                    { cout << " ARRAY IS NOT EMPTY\n"; i=-1; }
                }
            }
    }

    check=0;

}

cout << "\n\n\n\n";

return 0;

}

那么,你能帮我计算每个过程的等待时间 ......?

您应该使用http://cpp.sh/在线运行此代码。

1 个答案:

答案 0 :(得分:0)

请仔细阅读以下内容:How to Calculate Execution Time of a Code Snippet in C++

ctime非常有用,我很高兴您将来会在多线程案例中使用它。