Module pipe

Pipes allow exchanging messages. Messages are Prolog terms and are copied. An unbounded queue can be created by the predicate pipe_new/1. A bounded queue can be created by the predicate pipe_new/2. Pipes need not be explicitly destroyed, they will automatically be reclaimed by the Java GC when not anymore used. Threads waiting for a pipe can be interrupted.

Example:
?- queue_new(1, Q), pipe_put(Q, p(X)), pipe_take(Q, R).
Q = 0ra2a372,
R = p(_A)

The predicates pipe_put/2 and pipe_offer/[2,3] allow sending a message to a bounded queue. The predicates will block, fail or timeout when the bounded queue is full. The predicate pipe_put/2 can also be used for unbounded queues and will never block. The predicates pipe_take/3 and pipe_poll/[2,3] allow getting a message from a pipe. The predicates will block, fail or timeout when the pipe is empty.

The following queue predicates are provided:
pipe_new(Q):
The predicate succeeds for a new unbounded queue Q.
pipe_new(M, Q):
The predicate succeeds for a new bounded queue Q with maximum size M.
pipe_put(P, O):
The predicate succeeds for sending a copy of the term O to the pipe P.
pipe_offer(P, O):
The predicate succeeds for sending a copy of the term O to the bounded queue P. Otherwise the predicate fails.
pipe_offer(P, O, T):
The predicate succeeds for sending a copy of the term O to the bounded queue P in the timeout T. Otherwise the predicate fails.
pipe_take(P, O):
The predicate succeeds for getting a term O form the pipe P.
pipe_poll(P, O):
The predicate succeeds for getting a term O form the pipe P. Otherwise the predicate fails.
pipe_poll(P, T, O):
The predicate succeeds for getting a term O form the pipe P in the timeout T. Otherwise the predicate fails.

Kommentare