Question: 6 . 1 8 Consider a system consisting of processes P 1 , P 2 , dots, P n , each of which has a

6.18 Consider a system consisting of processes P1,P2,dots,Pn, each of which has
a unique priority number. Write a monitor that allocates three identical
line printers to these processes, using the priority numbers for deciding
the order of allocation.
Answer: Here is the pseudocode:
monitor printers {
int num_avail =3;
int waiting_processes [MAX_PROCS] ;
int num_waiting;
condition c;
void request_printer (int proc_number){
if (num_avail >0){
num_avail--;
return;
}
waiting_processes [num_waiting]= proc_number;
num_waiting++;
sort (waiting_processes);
while (num_avail ==0 &&
waiting_processes [0]!= proc_number)
c.wait () ;
waiting_processes [0]=
waiting_processes [num_waiting-1] ;
num_waiting-- ;
sort (waiting_processes) ;
num_avail--;
}
void release_printer(){
num_avail++;
c.broadcast () ;
}
}
 6.18 Consider a system consisting of processes P1,P2,dots,Pn, each of which

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!