Re: Multiple instances for embedded prolog interpreter
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 07/23/2013 02:22 PM, Stefan Radomski wrote: > Hey there, > > we embedded SWI prolog as a logic engine via its C++ interface and > it's working great. But we do need more than one instance of the > PLEngine or at least distinct states. Seeing that PL_initialise will > just initialize a global prolog interpreter, and the foreign > predicates will not receive any kind of callbacks, we figured that > there can only ever be one instance per runtime. Yes. There is no plan to change that either, although it wouldn't be terribly complicated because there are only a few global variables that contain structures holding the whole lot together. > If that's the case, can we "simulate" multiple instances i.e. by > swapping the interpreters state before calling any of the PL* > functions? We do not necessarily need concurrency, just distinct > states. We pondered about using several PLFrames to achieve something > like that but it seems that they will just "rollback" any term > references when closing. Frames merely control the scope of term_t (PlTerm) handles. What you need are engines. Actually, the terminology is a bit misleading because the one and only Prolog instance in the C++ interface is called engine. It predates the introduction of multiple engines in SWI-Prolog ... I think what you want is what is described in http://www.swi-prolog.org/pldoc/man?section=threadmanymany Don't be misguided by the threading; you can use this stuff just as well in a single thread. Be careful that you do not pass term_t (PlTerm) handles created on one engine to another one. It will crash. Note that the engines have the same sharing behavior as multiple Prolog threads, so while writing your Prolog code you must program as if you are running in a thread. This mainly refers to dynamic code: :- dynamic is shared, :- thread_local is not. Enjoy --- Jan > > If this issue has been discussed previously, please be so kind as to > provide a link. > > Best regards Stefan Radomski > > > --- FB20 Telecooperation | Darmstadt University of Technology > Hochschulstr. 10 | D-64289 Darmstadt Germany | Room S2|02 / A108 Tel > +49 (6151) 16-6670 | Fax +49 (6151) 16-3052 > > _______________________________________________ SWI-Prolog mailing > list [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog >