From nobody@lists.bilkent.edu.tr Thu Sep 27 13:16:13 2001
Received: from lists.bilkent.edu.tr (lists.bilkent.edu.tr [139.179.10.6])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8RBFxv15295
	for <prolog@swi.psy.uva.nl>; Thu, 27 Sep 2001 13:16:00 +0200 (MET DST)
Received: (from nobody@localhost)
	by lists.bilkent.edu.tr (8.9.3/8.9.3) id NAA05033;
	Thu, 27 Sep 2001 13:15:27 +0300
Date: Thu, 27 Sep 2001 13:15:27 +0300
Message-Id: <200109271015.NAA05033@lists.bilkent.edu.tr>
From: mdonder@cs.bilkent.edu.tr
To: prolog@swi.psy.uva.nl
X-Mailer: BasiliX v0.9.7 -- http://www.basilix.org
Subject: [SWIPL] Calling Prolog from foreign threads!


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

