next up previous
Next: Indirect Naming Schemes Up: No Title Previous: Producer-Consumer (as message passing)

Producer Consumer with Flow Control

  figure64
Figure:

Process PRODUCER
 var b: bufferpointer ;
 begin
   loop
    receive(CONSUMER,b); {get empty buffer}
    produce(b^) ;
    send(CONSUMER,b) ;
   end
 end 

Process CONSUMER
 const maxbuff = 6 ; {maximum buffers}
 var b : bufferpointer;
     i : integer ;
 begin
   for i:=1 to maxbuff do
   {initially, send empty buffers to producer}
    new(b) ;
    send(PRODUCER,b)
   end ;
   loop
    receive(PRODUCER, b) ;
    consumer(b^) ;
    send(PRODUCERm b) {return empty buffer}
   end;
end ;



Omer F Rana
Tue Feb 11 19:19:52 GMT 1997