Below are the pseudocodes for a variation of the solution for the producer-consu
ID: 3597699 • Letter: B
Question
Below are the pseudocodes for a variation of the solution for the producer-consumer problem. Explain what kind problem will happen?
full = new CSemaphore(0);
empty = new CSemaphore(N);
Producer process
while(true) {
. . .
produce a data item
. . .
empty.wait();
. . .
Write a data item to the buffer
. . .
full.signal();
. . .
}
Consumer process
while(true) {
. . .
full.wait();
…
Remove a data item from buffer
…
empty.signal();
// consume the data item
}
Explanation / Answer
full = new CSemaphore(0);
empty = new CSemaphore(N);
Producer process
while(true) {
. . .
produce a data item
. . .
empty.wait();
. . .
Write a data item to the buffer
. . .
full.signal();
. . .
}
Consumer process
while(true) {
. . .
full.wait();
…
Remove a data item from buffer
…
empty.signal();
// consume the data item
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.