If someone could help me finish this function it would be much appreciated becau
ID: 669387 • Letter: I
Question
If someone could help me finish this function it would be much appreciated because I have no idea what I am doing... Program involves a linked list of characters and this function needs to implement a schedule....
#include "scheduler.h"
// Scheduler Simulation
// Simulates a process scheduler for a collecdtion of tasks
// Parameters:
// tasks (modified process array)description of tasks to run
// arrival (input int array) arrival in simulation time
// size (input int) number of elements in arrays
// allowance (input int) maximal CPU allowance
// (a large 'allowance' simulates First Come First Served)
// Each Process includes a history of its activity which is
// pupulated during the simulation and displayed afterwards.
//
// The scheduler includes a readySet of processes that are currently
// wishing to use the CPU, and a future list of events that will
// occur later in the simulation. A simulation clock advances to
// identify which events occur in which order.
void Scheduler::runScheduler( Process tasks[], int arrival[], int size, int allowance )
{
int pid; // process wanting action
char nextAct; // and the action it wants
for (int i=0; i < size; i++)
{
future.insert( i, arrival[i], 'X'); // all want to run
tasks[i].restart(); // and start at beginning
tasks[i].addLog( arrival[i], '-'); // might have to wait
}
clock = 0; // initialize simulation clock
// repeat while anything is ready to run now or later
while ( !noneReady() || !future.empty() )
{
}
}
HERE IS THE HEADER file to go with it.. I cant change anything in the header file.
#include
using namespace std;
#include "histo.h"
// Process Scheduler
// This represents the part of an operating system that manages processes,
// choosing which to assign the CPU (assuming a single-processor system).
// It will maintain a collection of processes that are currently ready
// to use the CPU, and then choose which to run next.
//
// The time on the system clock is not required for this object,
// so all of the time fields in the linked list objects are set to zero.
class Scheduler
{
private:
ProcList readySet; // set of processes ready to run
ProcList future; // list of future events
int clock; // current clock time for simulation
public:
void addProcess( int procId )
{
readySet.pushBack( procId, 0, 'X');
}
void chooseProcess( int &procId )
{
char hold;
readySet.popFront( procId, hold );
}
bool noneReady()
{
return readySet.empty();
}
void runScheduler( Process[], int[], int, int );
};
Explanation / Answer
//Below Implements the scheduler simulation
//Complete method Scheduler::runScheduler, My modified code is in BOLD
//.. NOW THIS IS THE .CPP CODE SEGMENT THAT NEEDS TO BE MODIFIED ...
#include "scheduler.h"
// Scheduler Simulation
// Simulates a process scheduler for a collecdtion of tasks
// Parameters:
// tasks (modified process array)description of tasks to run
// arrival (input int array) arrival in simulation time
// size (input int) number of elements in arrays
// allowance (input int) maximal CPU allowance
// (a large 'allowance' simulates First Come First Served)
// Each Process includes a history of its activity which is
// pupulated during the simulation and displayed afterwards.
//
// The scheduler includes a readySet of processes that are currently
// wishing to use the CPU, and a future list of events that will
// occur later in the simulation. A simulation clock advances to
// identify which events occur in which order.
void Scheduler::runScheduler( Process tasks[], int arrival[], int size, int allowance )
{
int pid; // process wanting action
char nextAct; // and the action it wants
for (int i=0; i < size; i++)
{
future.insert( i, arrival[i], 'X'); // all want to run
tasks[i].restart(); // and start at beginning
tasks[i].addLog( arrival[i], '-'); // might have to wait
}
clock = 0; // initialize simulation clock
// repeat while anything is ready to run now or later
for(i=0;i<size;i++) //repeat this scheduling for each process i
{
while ( !noneReady() || !future.empty() ) //repeat until every process is ready to run
{
if(clock==arrival[i]) //if arrival time is equal to clock time
tasks.insert(i,arrival[i],'X'); //run the i-th process and update status to X-completed
}
clock++; //increment clock value
}
}
//Note: If you provide with code of "histo.h", I can run and show the snapshot of output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.