An asynchronous rendez-vous mechanism
\label{des/ext/proc}
\dlpindex{asynchronous rendez-vous}
The constructs presented so far are rather
transparant in the sense that we have taken care to
preserve, as far as possible, the semantics of ordinary Prolog
programs.\nop{
We admit that programmers may have to get used to
the hybrid nature of the constructs proposed.
}
We will now present some extensions by which the programmer
can profit more from the exploitation of the potential
parallelism in a problem.\ftn{
The constructs treated in this and the next section
are fairly low level.
We encourage the reader interested only in the major concepts of
DLP to skip these sections and
to continue with the next chapter.
}
For process creation, one may use the goal statement
\dlpindex{process creation}
\dlpindex{}
to request the object to which O refers to create
a process to evaluate the goal G. The variable Q thereafter
refers to that process.
And we introduce the goal
\dlpindex{resumptions}
\dlpindex{}
to request the answers delivered by the process to which
Q refers.
Semantics
The semantics of these statements can be easily explained
by remarking that the method call may considered to
be implemented as
O!G :- Q = O!G, Q?.
\nop{
However there are some intricacies, notably with respect
to the backtracking behavior.
First however we will motivate the usefulness of these extensions.
}
Using somewhat contradictory terminology,
a call of the form may be regarded as an
asynchronous method call,
since receiving the answers requires an explicit request of the form .
The variable Q is bound to a pointer to the process
evaluating G.
The goal G may be any goal -- for instance one that must
be explicitly accepted by an accept goal of the object
to which O refers.
We call the goal a resumption request, since it
delivers a resumption containing the answer substitutions
that result from the call.
Evaluating the resumption enables the possible variable bindings
of these answers to take effect in the current context.
See also section \ref{impl/comp/proc}.
Asynchronous calls allow the programmer to achieve some
extra parallelism, since the newly created process
runs independently of the invoking process,
which does not have to wait for an answer.
Such overlapping of processes is expressed by a goal of the form
[] , A,
The goal literal A represents an arbitrary literal or sequence of literal.
Between the creation of the process evaluating the goal G and stating the
resumption request to collect the answers to G,
the invoking process can perform any action whatsoever.
.so and
As described in section \ref{impl/comp/proc}, we have taken care to preserve
completeness in coupling the solutions produced by evaluating G
with the bindings resulting from the evaluation of A.
When backtracking occurs each alternative binding resulting from
the evaluation of A is coupled with all possible solutions of G.
However, if G has infinitely many solutions, A will never be tried
for producing alternative bindings.
And parallelism
\dlpindex{and parallelism}
\dlpindex{}
This mechanism of process creation and resumption allows to
define and-parallelism in a rather straightforward way, as
A\&B :- Q = self!B, A, Q?.
where self refers to the object evaluating the goal .
Such goals may however occur only in passive objects,
since only passive objects allow internal concurrency.
A typical example of the use of this kind of parallelism is the
following, familiar, quicksort program.
\lprog{qsort}{
.ds qsort.pl
}
Each nonempty list is divided into two sublists,
one with values less than the values in the other.
These are then sorted in parallel and the sorted sublists are concatenated.
The advantage of this approach is
that the programmer may restrict the cases where
parallel evaluation occurs by imposing extra conditions
(cf. [DG84]) as in
A\&B :- ground(B),!, Q = self!B, A, Q?.
A\&B :- A, B.
where splitting of a new process is allowed only when B is ground.
Note that the cut in the first clause is used
to avoid unwanted backtracking over the second solution of .
\nop{
As a shortcoming, however, we must note that
there is a certain incompleteness with respect to
the solutions
for A and B in a goal sequence of the form
.
Since the meaning of is by default attuned to
its use in implementing the synchronous
rendez-vous, explores all answer substitutions
resulting from the evaluation of a goal and thereafter
returns failure.
B and A are generated but only the solutions
composed of the first solution for B with any solution for A.
}