(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).