___chkstk()__ms () error

I am trying to simulate round robing scheduling.

I have narrowed down the error to line 137 and this fault:

___chkstk_ms () at /usr/src/debug/gcc-5.3.0-3/libgcc/config/i386/cygwin.S:137
137 /usr/src/debug/gcc-5.3.0-3/libgcc/config/i386/cygwin.S: No such file or directory.

I am not sure how to address this problem. From what I understand ___chkstk_ms() indicates that I am using over the 2MB alloted for the stack. I thought I addressed this issue when I dynamically allocated memory to the array of structs:

processData* aa;
aa = new processData[n];

Below is the code. Thank you in advance for any help.

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cstring>

using namespace std;

static int n = 1000;
int i;
int j;
int totalTime = 0;
float averageTurnAroundTime = 0;
float averageWaitTime = 0;
int processQueue[1000];
int timer = 0;
int front = 0;
int end = 0;
int queueCount = 0;


struct processData
{
int arrivalTime;
int durationTime;
int completionTime;
int turnAroundTime;
int waitTime;
int processNumber;
float netTurnAroundTime;
} temp;

void push (int process)
{
processQueue[end++] = process;
}

int pop()
{
int x;
x = processQueue[front++];
return x;
}

void check (struct processData a[])
{
while (a[j].arrivalTime <= timer && j < n)
{
queueCount++;
push(j++);
}
}

void display (struct processData a[])
{
for(i = 0; i < n; i++)
{
a[i].waitTime = a[i].turnAroundTime - a[i].durationTime;
a[i].netTurnAroundTime = (float)a[i].turnAroundTime / a[i].durationTime;
}

for (i = 0; i < n; i++)
{
averageTurnAroundTime += a[i].turnAroundTime;
averageWaitTime += a[i].waitTime;
}

averageTurnAroundTime = averageTurnAroundTime / n;
averageWaitTime += averageWaitTime / n;

cout << "Process #\tArrival Time\tduration Time\tCompletion Time\tTurn Around Time\tWait Time\tNet Turn Around Time" << endl;

for(int i = 0; i <= n; i++)
{
cout << a[i].arrivalTime << "\t" << a[i].durationTime << "\t" << a[i].completionTime << "\t" << a[i].turnAroundTime << "\t" << a[i].waitTime << "\t" << a[i].netTurnAroundTime << endl;
}

cout << "Average Turn Around Time: " << averageTurnAroundTime << "Average Wait Time " << averageWaitTime << endl;
}


void find(struct processData a[])
{
int tempDurationTime[n];
int flag = 0;
int count = 0;
int currentProcess;
j = 0;
int timeQuantum = 5;

for(i = 0; i < n; i++)
{
tempDurationTime[i] = a[i].durationTime;
}

timer = a[0].arrivalTime;
queueCount = 1;
push(j++);
while(timer <=totalTime)
{
if (flag == 1 || queueCount != 0)
{
if(flag == 0 && count == 0)
{
currentProcess = pop();
count = 0;
flag = 1;
}
tempDurationTime[currentProcess]--;
if(tempDurationTime[currentProcess] == 0)
{
timer++;
count = 0;
a[currentProcess].completionTime = timer;
flag = 0;
queueCount--;
check(a);
continue;
}
count++;

if(count == timeQuantum)
{
count = 0;
timer++;
check(a);
push(currentProcess);
flag = 0;
}
else
{
timer++;
check(a);
}
}
else
{
timer++;
check(a);
}
}
display(a);
}

int main ()
{
processData* aa;
aa = new processData[n];
ifstream infile;
int array[20];
int i = 0;
char pNum[10];
char aNum[10];
char dNum[10];

infile.open("job.txt", ifstream::in);
if (infile.is_open())
{
while (infile.good())
{
infile.getline(pNum, 256, ',');
aa[i].processNumber = atoi(pNum);
infile.getline(aNum, 256, ',');
aa[i].arrivalTime = atoi(aNum);
infile.getline(dNum, 256);
aa[i].durationTime = atoi(dNum);
i++;
}
infile.close();
}
else
{
cout << "Error";
}

for (i = 0; i < n; i++)
{
for (j = i; j >=1; j--)
{
if(aa[j].arrivalTime < aa[j-1].arrivalTime)
{
temp = aa[j-1];
aa[j-1] = aa[j];
aa[j] = temp;
}
else if (aa[j].arrivalTime == aa[j-1].arrivalTime)
{
if(aa[j].durationTime < aa[j-1].durationTime)
{
temp = aa[j-1];
aa[j-1] = aa[j];
aa[j] = temp;
}
}
}
}

totalTime += aa[0].arrivalTime + aa[0].durationTime;
for( i = 1; i < n; i++)
{
if(aa[i].arrivalTime > totalTime)
{
totalTime = aa[i].arrivalTime;
}
totalTime += aa[i].durationTime;
}

find(aa);

return 0;
}
And which line is line 137?
Sorry about that. Line 137 is:

137 else
138 {
139 timer++
140 check(a)
141 }

in the find function.
And which line is line 137?

Line 137 was in cygwin.S, but the file wasn't found by the debugging machinery.
https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/i386/cygwin.S
A stack trace would've been handy.

It seems likely the problem stems from your use of the non-standard extension that allows variable length arrays.

1
2
3
4
5
void find(struct processData a [])
{
    int tempDurationTime[n];                         // <--  Here.
    int flag = 0;
    int count = 0;


It doesn't look large enough to cause an issue to me, but that would be my best guess. Try replacing it with a vector (and doing the same with aa in main would be recommended over manually managing memory.)

Also, you have undefined behavior in the last loop in display. The condition should be i<n.

Why do you have a global variable named i? j? Why do you have so many global variables?
Last edited on
Topic archived. No new replies allowed.