load_files freezes in a multi threading application using JPL (Java calling Prolog)

Sergio Castro <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hello,

My scenario is the following:
I implemented a simple mechanism to overcome certain JPL limitations regarding multithreading applications (e.g., afaik a JPL query always has to be opened, its results traversed, and closed in the same thread).
So the main idea is that I keep a dedicated thread in a query wrapper, and all query operations are executed in the context of that thread.
Then the calling thread waits until the query thread completes, since the objective of the query thread is just to circumvent the JPL multithreading limitations regarding the need of being manipulated in the same Java thread.

If possible, I would like feedback regarding the correctness of this design. I am aware that this is of course less efficient than directly using a JPL query (since with my query wrapper there is a separate Java thread for each active query), but I find it useful for scenarios where I do not want to be constrained to traverse a JPL query in the same thread. I am happy to share the code if someone is interested btw.

However, I found a problem that appears in this setting.
If I execute the query below twice (using JPL), it freezes at the second call to load_files/2 (this is a simplification of my problem to keep the description simple, in my application I am in fact loading files using Logtalk, and the calls do not happen exactly one after another):

"writeln('before load_files'), flush_output, load_files('<filepath>/hello.pl', []), writeln('after load_files'), flush_output"

So the output I see is:

before load_files
% <filepath>/hello.pl compiled 0.00 sec, 2 clauses
after load_files
before load_files
<FROZEN HERE>

Note that the calls to load_files do not happen concurrently (afaik files should not be loaded concurrently). However, they do happen in different threads (synchronised between them). 
I also verified that if I execute everything in the same thread, then load_files does not freeze.

Any idea what may be the problem ?

Thanks,

Sergio
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.