<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
% The parent transaction forces two interacting processes to execute
% concurrently while synchronizing themselves.  It is modelled on
% Example 4 in my DBPL'97 paper.

trans(parent) :- conc(process(a),process(b)).

trans(process(a)) :- seq(task(a,1),
                      seq(ins(start(b2)),
                       seq(task(a,2),
                        seq(start(a3),
                             task(a,3))))).

trans(process(b)) :- seq(task(b,1),
                      seq(start(b2),
                       seq(task(b,2),
                        seq(ins(start(a3)),
                             task(b,3))))).

trans(task(I,J)) :- monitor(task(I,J)).

% Before executing the parent transaction a second time, cleanup the
% database by executing the following transaction.
%
trans(cleanup) :- seq(del(start(b2)),del(start(a3))).


% declare start/1 to be a base predicate.
%
start(X) :- db(start(X)).


% The following dummy rules let Prolog know that certain predicates
% are defined.
%
parent :- fail.
process(dummy) :-fail.
task(dummy,dummy) :- fail.
cleanup :- fail.
</pre></body></html>