Like recordz/2, this predicate records the term Value at the end of the list of terms recorded under Key.
In addition, this predicate, together with record_wait_remove/3, implements a bounded queue with synchronisation between concurrent threads.
If there are already Max (or more) recorded terms in the queue, the predicate blocks until an invocation of record_wait_remove/3 (in another thread) reduces the queue length to below Max. If this does not happen within Timeout seconds, the predicate fails.
Conversely, adding a new entry with this predicate unblocks all currently blocking invocations of record_wait_remove/3 on the same Key.
% Produce data in the main engine, and send it via a record-queue
% to a concurrently running engine thread for consumption
produce_consume(N) :-
record_create(Q),
engine_create(E, []),
engine_resume_thread(E, consume(Q)),
produce(Q, N).
produce(Q, N) :-
( for(I,1,N), param(Q) do
writeln(producing(I)),
record_wait_append(Q, I, block, 20)
).
consume(Q) :-
record_wait_remove(Q, Msg, block),
writeln(consuming(Msg)),
consume(Q).