:- module(prod_cons,_,ciao(h)). main :- consumer(L)& , producer(10,L). producer(0,T) :- !, T = []. producer(N,T) :- N > 0, T = [N|Ns], N1 is N-1, report(N,produced), producer(N1,Ns). consumer(T) :- wait(T), consumer_body(T). consumer_body([]). consumer_body([H|T]) :- report(H,consumed), consumer(T). report(H,PC) :- worker(W), format('Worker ~d ~w ~d~n', [W,PC,H]), flush_output(user_output).