Please provide clear explanations and reasoning for both part a and part b. Ques
ID: 3710750 • Letter: P
Question
Please provide clear explanations and reasoning for both part a and part b.
Question: Using Semaphores In class we discussed a solution to the Producer-Consumer problem foe a bounded buffer using three semaphores (mutex, emptyBuffers, and fullBuffers): Producer o Consumer() { wait (emptyBuffers) i wait mutex) put 1 item in buffer signal (mutex); signal (fullBuffers) wait (fullBuffers) wait (mutex) take 1 item from buffer; signal (mutex) i signal (emptyBuffers) Given each of the following variations, say whether it is comect or incormect. If you say conrect explain any of the advantages and disadvantages of the new code If you say incorect. explain what could go wrong e trace through an example where t does not behave properly). a) Producer {) { Consumer wait (mutex) wait (fullBuffere) Wait (mutex); Mait (emptyBuffers) put 1 itom in buffer: signal (fullBuffers) take 1 item from buffer signal (emptyBuffers) aignal (mutex) signal (mutex) b) Consumer Producer o wait (fullBuffers); wait (mutex) wait (mutex) wait (emptyBuffers) put 1 item in buffer signal (ullBuffers) take 1 item from buffer; signal (emptyBuffers) signal (mutex) signal (mutex)Explanation / Answer
Solution:
code a will work fine:
Advantages:
Disadvantages:
b)
This suffers from deadlock
suppose fulbuggers is above 0 and emptybuffers is at 0 then if producer is preempted after mutex then customer will start waiting for mutex to be signalled and producer will start waiting for emtybuffer to be signaled which is a deadlock.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
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.