Re: load_files freezes in a multi threading application using JPL (Java calling Prolog)
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 03/14/2014 05:27 PM, Sergio Castro wrote:
> 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.
I don't know. Technically, I guess this should be possible, but I wonder
what requirement justifies this complication. Can you give a scenario
where yiou would like to do this?
> 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.
load_files/2 can be called concurrently. Additional threads trying to
load a file while this is in progress will wait for the initiating
thread. The above works find in pure Prolog, so I assume the culprit
is JPL or your wrapper.
> Any idea what may be the problem ?
Typically, attach e.g., gdb and see which threads are blocking where.
That might give a clue.
Cheers --- Jan
>
> Thanks,
>
> Sergio -------------- next part -------------- HTML attachment
> scrubbed and removed _______________________________________________
> SWI-Prolog mailing list [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>