Question: [Points 3] What is the purpose of a condition variable in a monitor? How is the condition variable implemented? Explain your answer using an example.
![[Points 3] What is the purpose of a condition variable in](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f32ff6ccf00_55866f32ff652050.jpg)
[Points 3] What is the purpose of a condition variable in a monitor? How is the condition variable implemented? Explain your answer using an example.
[Points 3] In the monitor solution to the dining-philosophers problem (Figure 5.18), what happens when a process i calls test(i). In other words, what is being done in test(i)?
Q2.
Answer the following in the context of semaphores.
[Points 3] Write a piece of code to implement a solution for critical section problem using semaphores (with wait and signal operations). (Hint: similar to Petersons solution but using semaphores)
[Points 3] What are the advantages (if any) of using the above solution with semaphores instead of the one proposed by Peterson.
228 Chapter 5 Process Synchronization monitor DiningPhilosophers enum THINKING, HUNGRY, EATING) state C5]; condition self [5]; void pickup (int i) f state Cil HUNGRY tests (i); if (state [i] EATING) self [i] wait(); void putdown (int i) state [i] THINKING test (Ci 4) 5); tests ((i 1) 5); void test (int i) if ((state CCi 4) 5] EATING) && (state [i] HUNGRY) && (state (i 1) 5] EATING)) state [i] EATING self [i] signal); initialization code for (int i 0; i 5; i++) state[i] THINKING Figure 5.18 Amonitor solution to the dining-philosopher
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
