/*-------------------------------------------------------------------------
    program: producer/consumer problem (unbounded single-buffer)
    file:    pcusb
    date:    December 97
    author:  Pablo Lopez (lopez@lcc.uma.es)
             Dept. of CS
             University of Malaga, SPAIN
 
    sample goal:
        go([1,2,3],O)
-------------------------------------------------------------------------*/

module pcusb.

% linearity assures mutual exclusion access to buffer

producer([I|Is]) # buffer(B)
      <= insert(I,B,BI)
      *- producer(Is) # buffer(BI).

producer([]) *- bot.

consumer(Os) # buffer([I|B])
      <= insert(p(I),Os,OsO)
      *- consumer(OsO) # buffer(B).

consumer(Os) # buffer([]) # result(Os).

insert(X,[],[X]).
insert(X,[Y|Ys],[Y|Zs]) <= insert(X,Ys,Zs).

go(I,O) *- producer(I) # consumer([]) # buffer([]) # result(O).


