Question regarding cpp interface & thread safty


I have yet to write the hello world example,
but i have a very basic usage question regarding swi-prolog’s cpp interface.

I whish to write a program that executes 2 queries in parallel in two different threads ( on linux , ubuntu 16).

According to what i’ve seen in the documentation , multithreading is supported,
but I did not fully understand what is shared between threads :

" Prolog threads have their own stacks and only share the Prolog heap : predicates, records, flags and other global non-backtrackable data."

are asserted facts shared between threads?
( my requirement is that asserted data will not be shared).


See section 10.3.3 of Thread Communication, if your predicates are declared thread_local, then your asserted facts will not be shared.

Thank you Ian,

Could you also possibly clarify another issue -
“I wish to execute two queries in parallel in two different threads using cpp on ubuntu 16”

but the documentation i found is a bit confusing :

  1. manual section=cpp-embedding :
    " In some applications, there is a main-program and we want to use Prolog as a logic server . For these applications, the class PlEngine has been defined.

Only a single instance of this class can exist in a process. When used in a multi-threading application, only one thread at a time may have a running query on this engine."

  1. manual section=foreignthread:
    " If you are using SWI-Prolog as an embedded engine in a multithreaded application you can access the Prolog engine from multiple threads by creating an engine in each thread from which you call Prolog."

does “2” describe the c interface while “1” describe c++?
and if so, how can I access the c interface using a cpp compiler ?