Producer / Consumer : unbounded buffer
append
buffer[in]:= indata;
in := in + 1;
end append;
take
outdata:= buffer[out];
out := out + 1;
end take;
Initialization: semaphores: mutex = 1; Full = 0;
integers : in = 0; out = 0;
Repeat
produce indata;
wait( mutex );
append;
signal( mutex );
signal( Full );
Forever
Repeat
wait( Full );
wait( mutex );
take;
signal( mutex );
consume outdata;
Forever
Producer
Consumer
Does it matter to switch the two signals in the producer ?
Does it matter to switch the two waits in the consumer ?
Previous slide
Next slide
Back to first slide
View graphic version