Subject: [SWIPL] Calling Prolog from foreign threads!

From: [email-masked]
Date: Thu, 27 Sep 2001 13:15:27 +0300

I have been working on a project, where I create threads in Java and call a C
function passing some parameters within each thread. The C function called was compiled as a library from which Prolog is envoked to make queries on some prolog files. For each Java thread, the same file that contains prolog
rules is loaded. However, each thread may load different files consisting only of facts, dynamically because threads may process different sets of data (facts).
 
I read that any foreign thread can create its own Prolog engine for dealing with 
calling Prolog from C-code. I would like to use the C   interface of SWI-Prolog
within the C library function I make a call to in Java threads using JNI because my code is mostly C  . My question is "Can I create independent Prolog engines 
from my C library function that runs within the scope of a Java thread to pose
queries on possibly different sets of dynamically loaded Prolog files containing only facts?" Since all the instants of Prolog engines will be run on separate foreign threads, I would also have to load the same Prolog file that contains rules to process facts. And, this would create some redundancy, which is not so much of a problem considering that the number of threads will not be a great number and 
that the rules file is not very big.
 
What are the drawbacks of this approach I plan to implement using foreign threads? And, is there any other way of accomplishing this task more efficiently and effectively (Note that if I were to use Prolog threads, then I would have to find a away to make the facts-base of each thread independent from each other. Otherwise, threads would use a shared factsbase, whihc is not acceptable for me)?
 
I would also be greatful if someone could e-mail me example code for using multithreading support of SWI-Prolog in C   code using native C-thread calls.
 
Mehmet Emin Donderler
 
Mehmet Emin Donderler
Ph.D. Candidate of CS
Bilkent University