Producer / Consumer : Bounded Buffer
append
buffer[in]:= indata;
in := ( in + 1 ) mod N;
end append;
take
outdata:= buffer[out];
out := (out + 1) mod N;
end take;
Repeat
produce indata;
wait( Empty );
wait( mutex );
append;
signal( mutex );
signal( Full );
Forever
Repeat
wait( Full );
wait( mutex );
take;
signal( mutex );
signal( Empty );
consume outdata;
Forever
Producer
Consumer
Initialization: semaphores: mutex = 1; Full = 0; Empty = N;
integers : in = 0; out = 0;
Previous slide
Next slide
Back to first slide
View graphic version