Question: 2 . [ 3 0 points ] Synchronization 1 ) ( 1 5 points ) Suppose that there are n processes wanting to execute a

2.[30 points] Synchronization
1)(15 points) Suppose that there are n processes wanting to execute a critical section. We would like to impose a strict ordering execution of the processes as P1, P2,... Pn, P1, p2.... Please sketch the code with the use of binary semaphores to enforce the ordering. (Hint: the simple solution is that you need n binary semaphores with proper initialization)
Process P1:
while (TRUE){
BLANK1;
Critical Section
BLANK2;
} Process P2:
while (TRUE){
BLANK3;
Critical Section
BLANK4;
} Process Pi:
while (TRUE){
BLANK5;
Critical Section
BLANK6;
} Process Pn:
while (TRUE){
BLANK7;
Critical Section
BLANK8;
}
1)(15 points) In the following code, three processes synchronize with three semaphores L, M, R to produce output.
/* Initialize the three binary semaphores */
semaphore L =1;
semaphore M =0;
semaphore R =0;
/* random() function return a random float value that is greater than 0 and less than 1 with equal probability */
/* Process 1*/
while (true){
wait(L);
printf(A);
signal(R);
}
/* Process 2*/
while (true){
wait(R);
printf(B);
x = random();
if (x 0.5)
signal(L);
else
signal(M);
}
/* Process 3*/
while (true){
wait(M);
printf(C);
printf(D);
x = random();
if (x 0.4)
signal(L);
else if (x 0.8)
signal(R);
}
Please answer the following questions.
A)(2 points) What is the minimum length (minimum number of characters) of output?
B)(3 points) Is ABABCDBACD a possible output sequence when this set of processes runs? If it is possible, please calculate the probability, if not, explain why.
C)(3 points) Is ABCDABABCD a possible output sequence when this set of processes runs? If it is possible, please calculate the probability, if not, explain why.
D)(3 points) What is the probability that exactly two Cs are printed on the screen?
E)(4 points) What is the probability that exactly two Bs are printed on the screen?
2 . [ 3 0 points ] Synchronization 1 ) ( 1 5

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!