GUI applications written in XPCE can benefit from Prolog threads. Where XPCE 6 and earlier allowed only one Prolog thread to interact with XPCE, XPCE 7 and later allow multiple threads, but only one may be processing inside XPCE at any point in time. In other words, sending a message to XPCE requires obtaining the XPCE global lock, but if the method calls out back to Prolog, this lock is released and other Prolog threads may send messages to XPCE. This model is comparable to the Python GIL.
Due to the underlying SDL library, window and display related operations must be executed on the process main thread and GUI events originate from the (SDL) main thread. Other Prolog threads may execute goals in the SDL event loop and (thus) in the main thread using in_pce_thread/1 and in_pce_thread_sync/1.
SWI-Prolog/XPCE can operate in two setups. One is the console
application swipl that connects its I/O to a terminal (or Windows
console). In this setup, XPCE event processing is interleaved with
reading from the terminal. This implies that the GUI is not responsive
while a Prolog goal is running. Alternatively,
swipl-win is a GUI application that runs the Prolog REPL
(toplevel) loop in a Prolog thread connected to a terminal implemented
in XPCE (called Epilog). Now, the GUI runs in the process main
thread and interactive Prolog queries run in the thread connected to the
Epilog terminal, called conN. In this setup the
GUI remains responsive while user queries execute. The Epilog terminal:
xterm-256color escape sequences.
0xffff)
Unicode code points, Unicode (color) Emoji, double-width characters and
Unicode combining marks. It also provides a Unicode symbol
picker through the background menu.
conN
named thread. Epilog windows can be started using epilog/1,
by splitting an existing one horizontally or vertically or by creating a
new one through the menu. This allows for checking status and progress
of other threads (see tbacktrace/1
and
listing/2)
as well as running and debugging several goals simultaneously.
If SWI-Prolog was started as swipl, it may open an Epilog window by running epilog/0. See also section 4.35.4.
Note that in_pce_thread_sync/1 is slow and is typically only required for operations that act on windows or the display. A warning is printed if an SDL operation that may only be called from the main thread is called from another thread. Many common operations that require to be called in the main thread are automatically proxied to the main thread.