next up previous index
Next: Parallel Cuts Up: Parallel Execution Previous: Controlling and Analysing the   Index

Parallelism and Side Effects

In the current version, all side effect builtins like assert, record, setval and the I/O predicates work on resources that are shared between the workers and are accessed in a mutually exclusive way. For example, when two workers write onto a stream at the same time, the access will be sequentialised such that one of them writes first, and then the other. The order is unspecified. It is however, expected that the internal database builtins (such as assert and retract) will not be fully supported in the next major release (which will allow the system to execute on distributed memory platforms).

The current version also provides an explicit mutual exclusion primitive mutex/2. It can be used to make a sequence of several goals atomic, ie. to make sure that the execution of a piece of code is not interleaved with the execution of similarly protected code on other workers. For example, the following code will make sure that every list is printed in one chunk, even when several workers execute different instances of atomic_write_list/1 in parallel:

:- mutex_init(my_lock).
atomic_write_list(List) :-
    mutex(my_lock, write_list(List)).
write_list([]) :- nl.
write_list([X|Xs]) :- writeln(X), write_list(Xs).


next up previous index
Next: Parallel Cuts Up: Parallel Execution Previous: Controlling and Analysing the   Index

1999-08-06