Round Robin Problem

Page 1 of 1

1 Replies - 1123 Views - Last Post: 21 March 2013 - 10:34 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=316289&amp;s=c61afa17e1fb8ce2f7a633bc0e3b9880&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 darealmzm

Reputation: 0
• Posts: 28
• Joined: 29-October 12

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.

```
#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;
}

```

Is This A Good Question/Topic? 0

Replies To: Round Robin Problem

#2 #define

• Duke of Err

Reputation: 1632
• Posts: 5,751
• Joined: 19-February 09

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.