Consider the solution to the infinite-buffer producer/consumer problem defined in Figure 5.10. Suppose we have the
(common) case in which the producer and consumer are running at roughly the same speed. The scenario could be:
Producer: append; semSignal; produce;...;append; semSignal; produce;…; Consumer: consume;...; take; semWait; consume;…; take; semWait; ...
The producer always manages to append a new element to the buffer and signal during the consumption of the previous element by
the consumer. The producer is always appending to an empty buffer and the consumer is always taking the sole item in the buffer.
Although the consumer never blocks on the semaphore, a large number of calls to the semaphore mechanism is made, creating
considerable overhead.
Construct a new program that will be more efficient under these circumstances. Hints: Allow n to have the value -1, which is to mean
that not only is the buffer empty but that the consumer has detected this fact and is going to block until the producer supplies fresh
data. The solution does not require the use of the local variable m found in Figure 5.10.
Figure 5.10 A Correct Solution to the Infinite-Buffer Producer/Consumer Problem Using Binary Semaphores
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.