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

please i need help Consider the below code of process P1 and P2, where S1 and S2

ID: 3593407 • Letter: P

Question

please i need help


Consider the below code of process P1 and P2, where S1 and S2 are two semaphores initialized to 0 and A10, A20, B10, B2() are four functions Semaphore S1 0 Semaphore S2 0 P2 P1 ( A10; Up(S2); Down(S1): B10 A20 Up(S1): Down(S2); B2) 1. What is the order of execution of the functions A1, A2, B1 and B2 that has been imposed by the use of semaphores? 2. Provide the code of a process Pi, that ensures the same kind of execution order for N processes, where Pi executes the functions Ai) and Bi().

Explanation / Answer

Q1.) This code only ensures that A1 and A2 run Before B1 and B2. A1 and A2 can run in any order as os can give any of the processes to go first and P1 and P2 are made dependent on each other for running B1 and B2 using semaphores.Similarly, B1 and B2 can also run in any order.

Q2.) We can define S array with 1 to n index and set its value to 0. A function all_up() which Return True if all elements in the array are 1 else False.This will ensure that all Ai are run before Bi and there is no order of execution.

Pi {
Ai();
UP(S[i]);
while(!(all_up(S)));
Bi();
}

If you have any confusion or do not agree with solution please comment.I am available to help.Thank you.