SWI-Prolog multithreading is based on standard C-language
multithreading support. It is not like ParLog or other parallel
implementations of the Prolog language. Prolog threads have their own
stacks and only share the Prolog heap: predicates, records,
flags and other global non-backtrackable data. SWI-Prolog thread support
is designed with the following goals in mind.
- Multi-threaded server applications
Todays computing services often focus on (internet) server applications.
Such applications often have need for communication between services
and/or fast non-blocking service to multiple concurrent clients. The
shared heap provides fast communication and thread creation is
relatively cheap.68On an dual
AMD-Athlon 1600, SWI-Prolog 5.1.0 creates and joins 4,957 threads per
second elapsed time.
- Interactive applications
Interactive applications often need to perform extensive computation. If
such computations are executed in a new thread, the main thread can
process events and allow the user to cancel the ongoing computation.
User interfaces can also use multiple threads, each thread dealing with
input from a distinct group of windows. See also section
8.7.
- Natural integration with foreign code
Each Prolog thread runs in a native thread of the operating system,
automatically making them cooperate with MT-safe foreign-code.
In addition, any foreign thread can create its own Prolog engine for
dealing with calling Prolog from C-code.
SWI-Prolog multi-threading is based on the POSIX thread standard
Butenhof,
1997 used on most popular systems except for MS-Windows. On
Windows it uses the
pthread-win32
emulation of POSIX threads mixed with the Windows native API for
smoother and faster operation.
Section Index