Prev No Next Up Home Keys Figs Search New

Forking

Appeared in Volume 8/4, November 1995

Keywords: parallelism.

keller@muddcs.cs.hmc.edu
Robert M. Keller
6th July 1995

Philip Thrift wrote:

Is there a fork predicate in Quintus Prolog (or other Prolog). For instance:

fork(Pid)

It fails if nonvar(Pid); Creates a copy (child) of current (parent) process, instantiating P to 0 in the child process, and a positive integer to the parent; Pid instantiated to -1 if cannot create a child; Succeeds only once.

There is something called the Quintus Multiprocessing Package that was released with the Sequent release of QP 2.x some years ago. Although this package also works with some other Unix implementations, such as SunOS and Solaris, I don't believe that Quintus ever packaged it up for general use. But if you write to them, you might be able to get a copy of the library, which consists of a C interface and a bunch of Prolog predicates. Among them is:

mp_fork(Goal, ID)

which can be used to get the effect you want: Goal is any Prolog goal, which is executed deterministically, and ID is a variable which gets bound to a process id. The process thus created calls Goal in the context of a copy of the state of the parent process.

mp_fork/2 itself does not bind variables in Goal, so if you want answers back to the forking process, you need to use another mechanism. The Quintus package provides such a mechanism in the form of "channels" which are built on top of System V Message Queues. The manual for the package shows how to use the latter mechanism to get values back.

tarau@info.umoncton.ca
Paul Tarau
6th July 1995

Multi-BinProlog 3.45, (running on Solaris 2.x) available from clement.info.umoncton.ca, has a background process creation primitive, tellp/1 (see directory multi inside the distribution).

Its functionality is actually greater than fork. Communication with the child process is enabled through a high-level Linda-style blackboard. Processes are lightweight (actually Solaris threads) so that the usually wasteful copying of all data-areas as performed by fork based process creation is avoided. Creation of processes and blackboards on remote computers through the Internet is also possible using the same high-level interface.

micha@ecrc.de
Micha Meier
6th July 1995

MU-Prolog has a fork/1 predicate, NU-Prolog as well. In Eclipse, one can write call_c(fork, Pid).

Prev No Next Up Home Keys Figs Search New