Hardware Reference
In-Depth Information
,2,5)
( ′′ matrix-1 ′′ , 1, 6, 3.14)
(
(
′′
abc
′′
′′
family
′′
,
′′
is sister
′′
, Carolyn, Elinor)
Figure 8-47. Three Linda tuples.
, 2, 5) into the tuple space. The fields of out are normally
constants, variables, or expressions, as in
puts the tuple (
′′
abc
′′
out(
′′
matrix
1
′′
, i, j, 3.14);
which outputs a tuple with four fields, the second and third of which are deter-
mined by the current values of the variables i and j .
Tuples are retrieved from the tuple space by the in primitive. They are ad-
dressed by content rather than by name or address. The fields of in can be expres-
sions or formal parameters. Consider, for example,
in(
′′
abc
′′
,2,?i);
This operation ''searches'' the tuple space for a tuple consisting of the string
′′
, the integer, 2, and a third field containing any integer (assuming that i is an
integer). If found, the tuple is removed from the tuple space and the variable i is
assigned the value of the third field. The matching and removal are atomic, so if
two processes execute the same in operation simultaneously, only one of them will
succeed, unless two or more matching tuples are present. The tuple space may
even contain multiple copies of the same tuple.
The matching algorithm used by in is straightforward. The fields of the in
primitive, called the template , are (conceptually) compared to the corresponding
fields of every tuple in the tuple space. A match occurs if the following three con-
ditions are all met:
1. The template and the tuple have the same number of fields.
2. The types of the corresponding fields are equal.
3. Each constant or variable in the template matches its tuple field.
Formal parameters, indicated by a question mark followed by a variable name or
type, do not participate in the matching (except for type checking), although those
containing a variable name are assigned after a successful match.
If no matching tuple is present, the calling process is suspended until another
process inserts the needed tuple, at which time the called is automatically revived
and given the new tuple. The fact that processes block and unblock automatically
means that if one process is about to output a tuple and another is about to input it,
it does not matter which goes first.
abc
′′
 
Search WWH ::




Custom Search