Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
So,as a part of a project, i am trying to create a SJF scheduling simulation using C++. i am posting a part of my code which i found online and implemented in mine.
For some reason the loop is infinite and i cant figure out why. Also if someone could explain what t and w variables are would be very helpfull.

C++
waittime[1]=0;
w=w+ data[1];
t=w;
S[1]=0;

while(w<tt)>
{

    i=2;
    while(i<= nPages)
    {
        if(S[i]==1 && arrival[i]<=t)
        {
            waittime[i]=w;
            cout<<"WaitTime"<<i<<"="<<waittime[i];
            S[i]=0;
            w=w+data[i];
            t=w;
            i=2;
        }
        else
            i++;
    }
}

//calculating average weighting Time
for(i=1;i<=nPages;i++)
    sumWaitTime=sumWaitTime+(waittime[i] - arrival[i]);
AverageWaitTime=sumWaitTime/nPages;
cout<<"Total Weighting Time="<<sumWaitTime<<"";
cout<<"Average Weighting Time="<<AverageWaitTime<<"";


Additional information: All S[i] and waittime[i] have been initialized as 1(meaning True) and 0 respectively. Arrival[i] and Data[i] (burst times) have values(from poisson and exponential distributions) and finaly Tt is the total time ( sum of all burst times)

Thanks in advance, Dimitris

source of code http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=11825&lngWId=3
Posted
Updated 30-Sep-13 9:48am
v4
Comments
Richard MacCutchan 1-Oct-13 4:30am    
You need to ask the author of the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900