|
The bounded buffer function, bbuffer, takes as parameters
a bound,
an input channel, inch, and
an output channel, opch,
and produces a buffer process.
The buffer process sits between the input and output channels and
smooths out variations in production and consumption rates in the usual way.
When the buffer is empty (size=0)
it will only accept from the input channel
an item (inch?x) to be stored.
When the buffer is full (size=bound)
it will only offer to pass on to the output channel
(opch!hd buff) the oldest item in the buffer.
When the buffer process is neither full nor empty it will
either accept another item or ("|") pass one on.
bbuffer = lambda bound. lambda inch. lambda opch.
let rec
add = lambda x. lambda L. {add element x to list L}
if null L then x::nil else (hd L)::(add x (tl L)),
bb = lambda size. lambda buff.
if size=0 then {empty}
inch?x -> bb 1 (x::nil)
else if size=bound then {full}
opch!hd buff -> bb (size-1) (tl buff)
else {neither full nor empty}
opch!hd buff -> bb (size-1) (tl buff) |
inch?x -> bb (size+1) (add x buff)
in bb 0 nil
{\fB Bounded Buffer. (incomplete program) \fP}
|
e.g. c1993
|
pfl...
| | |
choice |
|| | parallel |
-> | sequence |
? | input act |
! | output act |
chan | new channel |
|
|
|