module JoinFifo:sig..end
Concurrent fifo's offer blocking get operations.
More precisely, get operations on, active, empty fifo's are
blocking.
Fifo behavior can be observed in the simple situation where one agent (producer) is putting elements, while another agent (consumer) is getting them. Then the following guarantees hold:
close returns.type 'a t = {
|
put : |
(* | Put element into fifo. | *) |
|
get : |
(* | Get element from fifo. | *) |
|
close : |
(* | Close fifo, returns only when the fifo is empty | *) |
|
kill : |
(* | Close fifo, returns immediately, discarding any pending element. | *) |
val create : unit -> 'a tf be a fifo.f.put(x,k) put v into the fifo f. The channel
k receives a (boolean) message b, where:
b is true, then v was succesfully entered into f.b is false, then v could not be added to f.
That is, f have been closed or killed.f.get(k) retrieve one element from the fifo, The channel k
receives a ('a option) message, where:
None expresses that the fifo is closed.Some x expresses that element x is retrieved from the fifo.close and kill both close the fifo, but with different
behaviors as regards non-empty fifos.f.close() waits for the fifo to be empty before closing it and
returning.f.kill() is an asynchronous channel, sending a message on
f.kill closes the fifo immediately.f.close is for the producer to
signal the end of produced elements; while f.kill is for the consummer
to signal that it will not accept more elements.val create_prod_cons : unit -> 'a JoinCom.P.t * 'a JoinCom.C.tcreate_prod_cons () returns the pair prod,cons.
The producer prod has the get and kill operations,
while the consumer has the put and close operations.
Indeed, by the convention of module JoinCom,
prod produces data from the fifo, while cons consumes
data to feed the fifo.
module S:sig..end
val create_sync : unit -> 'a S.t'a t, but they hold synchronous channels (of functional
type)
put of type 'a -> unit either returns (when successful)
or raise the exception S.Closed.get follows the same behavior.close of type unit -> unit closes the fifo,
returning when the fifo is empty.