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 e are the standard functions discussed dequ in class. Assume they have been implemented correctly by one of the methods. Semaphore ni 0, mutex-1 number of items currently in the queue. mutex is used to provide critical section. Code of a Producer Code of a Consumer local var item; local var item; L1: produce (item). L2: P(mutex); M1: P(ni); L3: while qful 0 do M2: P(mutex), L4 Mmutex) go to L2) M3: deque (item) while loop ends here M4: V(mutex). L5: enque item) M5: consume (item); L6: V(mutex). L7: V(ni). M6: go to M1 L8: go to L1 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
Consider the Producer-Consumer problem Assume that there are 2 producers (P1 and P2) and 1 consumer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT