Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have no idea how to do this. The solution for the original problem is in textb

ID: 647383 • Letter: I

Question

I have no idea how to do this. The solution for the original problem is in textbook solutions, but that isn't what my teacher wants. I am supposed to write pseudocode using SEMAPHORE for the following:

Consider a system consisting of processes P1, P2, ..., Pn, each of which has

a unique priority number. Write a monitor that allocates three identical

printers to these processes, using the priority numbers for deciding the

order of allocation. (WRITE A SEMAPHORE SOLUTION.)

An explanation of this solution would be much appreciated and rewarded with points. Thank you very much for your time. I sincerely apprecaite it.

Explanation / Answer

Answer:

Monitor is essentially a class/structure which allows each process in their Queue/Priority number.

Implementation of Monitor using Semaphores:

A semaphore "x_sem" and an integer "x_count" are introduced, both initialized to zero. The wait and signal methods are then implemented as follows. (This approach to the condition implements the signal-and-wait ensuring that only one process at a time is active inside the monitor)

1) Function Wait()

x_count++;

if(next_count>3) // maximum printers 03 reached make wait

signal(next);

else

signal(mutex); // any printer is available then signaling to neighboour process

wait(x_sem);

x_count--;

End Function

2) Function Signal()

if(x_count>3) // maximum 03 printers allocation

{

next_count++;

signal(x_sem); // Signal to next process to use release printer

wait(next);

next_count--;

}
End Function

In this monitor only one process is entered base on priority numbers.

Eg:(Lowest priority is first, highest is last)

P1 - 02

P2 - 01

P3 - 03

1. First P2 is entered into monitor then all 03 identical printers are allocated to P2.

2. If P2 release any of 03 printers, that signal to next Process in queue i.e., P1.

3. If P2 & P1 using all 03 identical printers, there will be waiting of P3 in queue.

4. After any of P2 or P1 signal about release of printer, that is/are allocated to P3

                                 P3-3

                                 P1-2

                                 P2-1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote