next up previous Return to CLIP Main Page
Next: Active Modules / Active Up: Document: distrib_imperial Previous: Implementing and Using Blackboards

Producer-Consumer: Linda Version

(using CIAO BB primitives)

?- create_bb(B,local), N=10, 
   lproducer(N,B) @ alba &, lconsumer(B).

lproducer(N,B) :-
        lproducer(N,1,B). 

% second argument is message order
lproducer(0,C,B) :- !,
   linda:out(message(end(C)),B).
lproducer(N,C,B) :-
   N>0,
   linda:out(message(C,N),B),
   N1 is N-1,
   C1 is C+1,
   lproducer(N1,C1,B).

lconsumer(B) :- 
   lconsumer(1,B). 

lconsumer(C,B) :-
   linda:rd([message(end(C)),
             message(_,C)], T, B),
   lconsumer_data(T,B).

lconsumer_data(message(end(_)),B).
lconsumer_data(message(N,C),B) :-
   C1 is C+1,
   lconsumer(C1,B).



<herme@fi.upm.es>-< webmaster@clip.dia.fi.upm.es>
Last updated on Mon Mar 31 21:20:55 MET DST 1997