#include "handle_active_jobs.h"
void handle_active_jobs(int cycle, int quantum,
queue<ProcessRec>& process_q, StatsRec& results)
{
static ProcessRec active_job; // active job persists between cycles
static bool job_in_progress = false; // variable persists between calls
// if no job in progress and process q is empty,
// increment idle cycles and return immediately
if(process_q.size() == 0 && !job_in_progress)
{
if(global_verbose)
{
cout << setw(10) << ' ' << "no jobs in progress.\n";
}
results.idle_cycles++;
return;
}
// if no job in progress and process q not empty,
// then: get next job from queue
// set job's quantum_left to quantum
// set job_in_progress to true
if(!job_in_progress)
{
active_job = process_q.front();
process_q.pop();
active_job.quantum_left = min(active_job.time_needed,quantum);
job_in_progress = true;
}
if(global_verbose)
{
cout << setw(10) << ' ' << "Job " << active_job.id << " in progress. "
<< "quantum_left is: " << active_job.quantum_left << endl;
cout << setw(10) << ' ' << "Process Queue: [";
show_queue(process_q);
cout << "]\n";
}
// decrement active job's time_remaining and its quantum_left
// if active job is done: calculate the job's turnaround time and
// wait time and update the appropriate fields in the results struct
if (){
}
// if active job not done, quantum is expired, and other jobs are waiting:
// pre-empt the active job (put it back on the process queue and set
// job_in_progress to false)
if(!job_in_progress && process_q.size == quantum){
job_in_progress = false;
}
Round Robin Problem
Page 1 of 11 Replies - 104 Views - Last Post: 21 March 2013 - 10:34 PM
#1
Round Robin Problem
Posted 21 March 2013 - 09:38 PM
My instructor wants us to complete this code for tomorrow for this program. Whatever he explains in the comments we have to put in code. I can't figure out the last few steps. I know I have to use if statement but I'm not sure of how to implement that last few things he's asking for. Could someone please point me in the right direction. ANY help is appreciated!!! The header file is in the attachments.
Replies To: Round Robin Problem
#2
Re: Round Robin Problem
Posted 21 March 2013 - 10:34 PM
I would say that if the active job is done then the time_remaining will be zero.
If the quantum is expired then its quantum_left will be zero.
If the quantum is expired then its quantum_left will be zero.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|