2.4.2 Clients
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Transparent Inter-Process Communications (TIPC) libraries
        • The TIPC libraries: library(tipc/...)
          • library(tipc/tipc_linda): A Process Communication Interface
            • Clients
              • linda/0
              • linda/1
              • linda_client/1
              • close_client/0
              • linda_timeout/2
              • linda_timeout/1
              • out/1
              • in/1
              • in_noblock/1
              • in/2
              • rd/1
              • rd_noblock/1
              • rd/2
              • bagof_in_noblock/3
              • bagof_rd_noblock/3
              • linda_eval/1
              • linda_eval/2
              • linda_eval_detached/1
              • linda_eval_detached/2
              • tuple/1
              • tuple/2
              • tipc_linda_server/0
              • tipc_initialize/0
Availability::- use_module(library(tipc/tipc_linda)).
[det]linda_eval(:Goal)
[det]linda_eval(?Head, :Goal)
[det]linda_eval_detached(:Goal)
[det]linda_eval_detached(?Head, :Goal)
Causes Goal to be evaluated in parallel with a parent predicate. The child thread is a full-fledged client, possessing the same capabilities as the parent. Upon successful completion of Goal, unbound variables are unified and the result is sent to the Linda server via out/1, where it is made available to others. linda_eval/2 evaluates Goal, then unifies the result with Head, providing a means of customizing the resulting output structure. In linda_eval/1, Head, and Goal are identical, except that the module name for Head is stripped before output. If the child fails or receives an uncaught exception, no such output occurs.

Joining Threads: Threads created using linda_eval/(1-2) are not allowed to linger. They are joined (blocking the parent, if necessary) under three conditions: backtracking on failure into an linda_eval/(1-2), receipt of an uncaught exception, and cut of choice-points. Goals are evaluated using forall/2. They are expected to provide nondeterministic behavior. That is they may succeed zero or more times on backtracking. They must however, eventually fail or succeed deterministically. Otherwise, the thread will hang, which will eventually hang the parent thread. Cutting choice points in the parent's body has the effect of joining all children created by the parent. This provides a barrier that guarantees that all child instances of Goal have run to completion before the parent proceeds. Detached threads behave as above, except that they operate independently and cannot be joined. They will continue to run while the host process continues to run.

Here is an example of a parallel quicksort:

qksort([], []).

qksort([X | List], Sorted) :-
      partition(@>(X), List, Less, More),
      linda_eval(qksort(More, SortedMore)),
      qksort(Less, SortedLess), !,
      in_noblock(qksort(More, SortedMore)),
      append(SortedLess, [X | SortedMore], Sorted).