30 Linda—Process Communication

Linda is a concept for process communication.

For an introduction and a deeper description, see [Carreiro & Gelernter 89a] or [Carreiro & Gelernter 89b], respectively.

One process is running as a server and one or more processes are running as clients. The processes are communicating with sockets and supports networks.

The server is in principle a blackboard on which the clients can write (out/1), read (rd/1) and remove (in/1) data. If the data is not present on the blackboard, the predicates suspend the process until they are available.

There are some more predicates besides the basic out/1, rd/1 and in/1. The in_noblock/1 and rd_noblock/1 does not suspend if the data is not available—they fail instead. A blocking fetch of a conjunction of data can be done with in/2 or rd/2.

Example: A simple producer-consumer. In client 1:

     producer :-
            produce(X),
            out(p(X)),
            producer.
     
     produce(X) :- .....

In client 2:

     consumer :-
            in(p(A)),
            consume(A),
            consumer.
     
     consume(A) :- .....

Example: Synchronization

            ...,
            in(ready),  %Waits here until someone does out(ready)
            ...,

Example: A critical region

            ...,
            in(region_free),  % wait for region to be free
            critical_part,
            out(region_free), % let next one in
            ...,

Example: Reading global data

            ...,
            rd(data(Data)),
            ...,
     
     or, without blocking:
            ...,
            rd_noblock(data(Data)) ->
                  do_something(Data)
            ;     write('Data not available!'),nl
            ),
            ...,

Example: Waiting for one of several events

            ...,
            in([e(1),e(2),...,e(n)], E),
     %  Here is E instantiated to the first tuple that became available
            ...,