Consider the Producer-Consumer problem Assume that there are 2 producers (P1 and
ID: 3822923 • Letter: C
Question
Consider the Producer-Consumer problem Assume that there are 2 producers (P1 and P2) and 1 consumer (C1). The maximum number of items in the queue is 100. Consider the following solution The functions qfull enque and deque are the standard functions discussed in class Assume they have been implemented correctly by one of the methods Semaphore ni=0, mutex=1; /* ni= number of items currently in the queue.*/ /* mutex is used to provide critical section. */ Code of a Producer local var item: L1 produce(item); L2: P(mutex); L3: while qfull() do L4: {V(mutex); go to L2}; /* while loop ends here*/ L5 enque(item); L6: V(mutex); L7: V(ni); L8: go to L1 Code of a Consumer local var item; M1: P(ni); M2: P(mutex); M3: deque(item); M4 V(mutex); M5: consume(item); M6: go to M1 Will this solution work? (YES or NO). In case your answer is YES, give an explanation. In case the answer is NO, give an appropriate example that proves your answer. In either case, your answer should be within 100 words.Explanation / Answer
This solution does not work.
Assume following specific case.
Let queue is full and Producer is holding the mutex say P1.
P1 will go into critical section and execute code on L3. It will check for if queue is full or not if queue is full then it again loop back to L2 and again try to acquire lock on critical section. So it will continue to loop back this way .
Mean while consumer will wait for producer to release the lock which will not happen so dead lock situation will happen.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.