Process Synchronization
Producer-Consumer Problem:
Producer Process: produces information
Consumer Process: consumes the information
unbounded-buffer places no practical limit on the size of the buffer
bounded-buffer assumes that there is a fixed buffer size
Producer:
while (true)
{
/* produce an item and
put in nextProduced */
while (count == BUFFER_SIZE)
; // do nothing
buffer [in] = nextProduced;
in = (in + 1) % BUFFER_SIZE;
count++;
}
Consumer:
while (true)
{
while (count == 0)
; // do nothing
nextConsumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
count--;
/* consume the item in
nextConsumed */
}
Every process will have its Own critical section involving the shared data/variable.