Grrr. yet another one that is giving me fits. Suppose your friend wrote the foll
ID: 3883018 • Letter: G
Question
Grrr. yet another one that is giving me fits.
Suppose your friend wrote the following pseudocode for the producer/consumer problem. After studying carefully the code, you said that this code has two major design flaws. You also claimed that these two flaws can result in problem(s). Explain in detail the flaws and the problem(s) these flaws can create. program producerconsumer: var n: semaphore (: = 0): s: semaphore (: = 0): procedure producer: begin repeat produce: wait(s): append: signal(s): signal(n): forever end: begin (*main program*) parbegin producer: consumer: parend end. producer consumer: begin repeat wait(s): wait(n): take: signal(s): consume: forever end;Explanation / Answer
Champ, here is the answer for you. Let me know if you like it. If you think the answer needs improvement, please feel free to comment below. I shall be glad to help you till your problem is solved.
Case 1: Initialization
Since binary semaphore s is initialized as 0,
producer: wait(s); //waits here
consumer: wait(s); //also waits heredl
Once both processes comes to halt, which we have seen, the system is in deadlock condition.
Case 2: Deadlock:
consumer: wait(s);
consumer: wait(n);
takes
consumer: signal(s);
consumer: wait(s);
consumer: wait(n); //waits here
producer: wait(s); //waits here
at this position, both the processes comes to a halt creating deadlock
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.