helios, how is my device_start() function completely wrong. Please explain! I'm so confused! So I'm trying to delete end (a.k.a head) of the device queue.
And the head of my device queue is the temp that is returned in move_top() function.
In the ready-queue::move_top() function the head is never supposed to be NULL because there will be nothing to be moved then?
Still, it 's a really bad idea to have a path through your code that can return garbage to the caller. Add return NULL; before line 64 and print the value returned at line 115. I think you'll find that temp is NULL.
void device_queue :: device_start(){
PCB* temp = move_top();
if (temp != NULL){
if (end == NULL){
end = temp;
}
else{
begin->next=temp;
}
begin=temp;
}
else{
cout << "There are no devices";
}
}
The device_start function should be going to this:
cout << __func__ << " temp.pid is now: "<< temp -> pid << endl;
but it instead goes to: cout << __func__ << " returns NULL." << endl;
So you missed the point that Smac89 was making in the second post. By the way, I missed reading it when I made my comment in the sixth post. Then a version of the same point is made by dhayden made in the ninth post.
The device_start function should be going to this:
cout << __func__ << " temp.pid is now: "<< temp -> pid << endl;
but it instead goes to: cout << __func__ << " returns NULL." << endl;
Now you have proved to yourself that ready_queue :: move_top() is being called when head==NULL.
So are you seeing "There are no devices"?
Please select an indentation style and use it consistently. If you want help from others, make your code readable.
So now the problem is:
say I enter c1: So, process with PID 1 enters device.
say I enter c1: So, process with PID 2 enters device.
say I enter C1: So, done with process with PID 2 in device.
but should be done with process with PID 1 in device, and then done with PID 2 in device, not just last one. How to fix this?
ok so this is in my main:
1 2 3 4 5 6 7 8 9 10 11 12 13
case'c':
cin >>num;
if (num > c || num < 1){
cout << "this device doesn't exist" <<endl<<endl;
}
else
cdrws[num].device_start(rq.move_top());
cdrws[num].device_arrival();
break;
case'C':
cdrws[num].device_completion();
break;