Hi, small problem I'm having.
I've created an array of queues:
I know I could have used a vector of queues, but I think this will be easier to debug.
I can insert elements into the first element of the array:
But when I attempt to push into any other element, it doesn't put them in.
ie,
I'm using Visual Studio .NET 2003. In the debugger, it shows pqueue[0].c's _MAP as being referenced, but any of the other elements _MAP is shown as an undefined value.
Why? And How do I fix it?
Thanks for any help,
Jason
I've created an array of queues:
Code:
queue<Process> pqueue[NUM_PRIORITY_LEVELS];
I can insert elements into the first element of the array:
Code:
pqueue[0].push(p);
ie,
Code:
pqueue[2].push(p); //executes, but it doesn't actually appear
Why? And How do I fix it?
Thanks for any help,
Jason
Code:
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include "EXPQueue.h"
#include "Process.h"
#include "state.h"
#include "SchedulerProcess.h"
using namespace std;
//EXPQueue::EXPQueue() : ReadyState("Ready State (EXP)"){
EXPQueue::EXPQueue() : state("Ready State (EXP)"){
for(int i=0; i<NUM_PRIORITY_LEVELS; i++)
this->pqueue[i].size();
}
EXPQueue::~EXPQueue(){
}
// What to do when the clock ticks
void EXPQueue::clockTick(long currentTime) {
this->currentTime = currentTime;
}
// Store an existing process in the right queue
void EXPQueue::storeIntoQueue(Process p) {
//first determine what the new priority level should be and set it
int level = p.getTimeSliceLevel();
int start = p.getTimeSliceStart();
int end = p.getTimeSliceEnd();
int runTime = (int)(pow(2,level)*10);
int actualTime = end - start;
//runTime is how long it could have run for
if(runTime == actualTime) {
if(level<NUM_PRIORITY_LEVELS)
p.setTimeSliceLevel(++level);
}
else if(((double)actualTime/(double)runTime)<.5)
if(level>0)
p.setTimeSliceLevel(--level);
//then store it in the right level at the end
this->pqueue[p.getTimeSliceLevel()].push(p);
}
// Load what should be the next process from the Queue
Process EXPQueue::loadFromQueue() {
Process p;
// If the queues are not empty, load the first process, and store a copy in copy
if(!this->isEmpty()) {
p = this->getFront();
this->copy = p;
}
return p;
}
//Check if there are any processes
bool EXPQueue::isEmpty() {
for(int i=0; i<NUM_PRIORITY_LEVELS; i++)
if(!this->pqueue[i].empty())
return false;
return true;
}
//Check if there is more work to do (Keeps syntax similar in opening loop)
bool EXPQueue::getMoreToDo() {
for(int i=0; i<NUM_PRIORITY_LEVELS; i++)
if(!this->pqueue[i].empty())
return true;
return false;
}
//Return a copy of what's up front
Process EXPQueue::getFront() {
Process p;
//Get the first available process
for(int i=0; i<NUM_PRIORITY_LEVELS; i++)
if(!this->pqueue[i].empty()) {
p = this->pqueue[i].front();
this->pqueue[i].pop();
return p;
}
return p;
}
// Describe the state
string EXPQueue::toString() {
char temp[ARRAY_SIZE];
char temp2[20];
int nums[8];
int size = 0;
for(int i=0; i<NUM_PRIORITY_LEVELS; i++)
size += this->pqueue[i].size();
string info = this->name + ": Queued Processes = ";
info += itoa(size, temp, NUM_BASE);
if(!this->isEmpty()) {
info += this->getFront().toString();
for(int i=0; i<NUM_PRIORITY_LEVELS; i++)
nums[i] = this->pqueue[i].size();
}
sprintf(temp2, "%d %d %d %d %d %d %d %d",nums[0],nums[1],nums[2],nums[3],nums[4],nums[5],nums[6],nums[7]);
info += temp2;
return info + "\n";
}