| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I use prolog as logic engine in my C++ application with MT. I put my dynamic predicates in thread local storage and it works with 'thread_local' property. Now I want to have different sets of non- dynamic predicates ( sometimes even different implementations of the same predicates) in different running threads of prolog engine. Is there any way to do this? Documentation sais that thread_local are implicitly dynamic predicates. Unless I misunderstood it... Is there any property that would make static predicates thread_local? I figured out that I might use modules to workaround this situation. In this case I'd have separate module for each thread and import each predicate I want to this module. Is this correct approach? Although I'd prefer something cleaner/more simplistic... |
|
#2
| |||
| |||
| On 2008-08-01, pmitka <pmitka@gmail.com> wrote: > I use prolog as logic engine in my C++ application with MT. > I put my dynamic predicates in thread local storage and it works with > 'thread_local' property. Now I want to have different sets of non- > dynamic predicates ( sometimes even different implementations of the > same predicates) in different running threads of prolog engine. Is > there any way to do this? > > Documentation sais that thread_local are implicitly dynamic > predicates. Unless I misunderstood it... Yip, and it cannot be static: new threads start without clauses for the thread local predicates and and the end of the thread all clauses are deleted. > Is there any property that would make static predicates thread_local? No. I guess in theory this would be possible. > I figured out that I might use modules to workaround this situation. > In this case I'd have separate module for each thread and import each > predicate I want to this module. Is this correct approach? Although > I'd prefer something cleaner/more simplistic... That is the right approach. You put all the shared stuff in one or more modules. For each different context you load all the specific stuff into a dedicated module and you import the shared modules. Its not that hard :-) Cheers --- Jan |
|
#3
| |||
| |||
| On 1 Sie, 11:49, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote: > On 2008-08-01,pmitka<pmi...@gmail.com> wrote: > > > I useprologas logic engine in my C++ application with MT. > > I put my dynamic predicates in thread local storage and it works with > > 'thread_local' property. Now I want to have different sets of non- > > dynamic predicates ( sometimes even different implementations of the > > same predicates) in different running threads ofprologengine. Is > > there any way to do this? > > > Documentation sais that thread_local are implicitly dynamic > > predicates. Unless I misunderstood it... > > Yip, and it cannot be static: new threads start without clauses for > the thread local predicates and and the end of the thread all clauses > are deleted. > > > Is there any property that would make static predicates thread_local? > > No. *I guess in theory this would be possible. > > > I figured out that I might use modules to workaround this situation. > > In this case I'd have separate module for each thread and import each > > predicate I want to this module. Is this correct approach? Although > > I'd prefer something cleaner/more simplistic... > > That is the right approach. *You put all the shared stuff in one or > more modules. *For each different context you load all the specific > stuff into a dedicated module and you import the shared modules. *Its > not that hard :-) > > * * * * Cheers --- Jan Let's assume this situation I really can't find solution: 1. a.pl is a shared module: :-module(a,[]). :-export(tst). tst:- foo. 2. b.pl is: :-module(b,[]). :-export(foo). foo:- fail. It works if I consult both files and import 'a:tst' and 'b:foo' let's say to dynamic module 'aa' and call aa:tst. (result is fail) But when I'd like to have module 'bb' with shared predicate imported from 'a:tst' redefined foo predicate from file c.pl: 3. c.pl is: :-module(c,[]). :-export(foo). foo:- true. I consult c.pl and get error: ERROR: Cannot import c:bob/0 into module user: already imported from b When I tried to consult that files directly to module 'aa' or 'bb' I have an error: a:tst/0: Undefined procedure: a:foo/0 ERROR: However, there are definitions for: ERROR: aa:foo/0 ERROR: b:foo/0 How do I have to modify my code to make it work? Because certainly I don't know how to write call for 'foo' predicate in 'a' module to make it redifinable and how to load module files? By use_module, consult, import? |
|
#4
| |||
| |||
| On 2008-09-11, Pawel Mitka <pmitka@gmail.com> wrote: > On 1 Sie, 11:49, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote: >> On 2008-08-01,pmitka<pmi...@gmail.com> wrote: >> >> > I useprologas logic engine in my C++ application with MT. >> > I put my dynamic predicates in thread local storage and it works with >> > 'thread_local' property. Now I want to have different sets of non- >> > dynamic predicates ( sometimes even different implementations of the >> > same predicates) in different running threads ofprologengine. Is >> > there any way to do this? >> >> > Documentation sais that thread_local are implicitly dynamic >> > predicates. Unless I misunderstood it... >> >> Yip, and it cannot be static: new threads start without clauses for >> the thread local predicates and and the end of the thread all clauses >> are deleted. >> >> > Is there any property that would make static predicates thread_local? >> >> No. *I guess in theory this would be possible. >> >> > I figured out that I might use modules to workaround this situation. >> > In this case I'd have separate module for each thread and import each >> > predicate I want to this module. Is this correct approach? Although >> > I'd prefer something cleaner/more simplistic... >> >> That is the right approach. *You put all the shared stuff in one or >> more modules. *For each different context you load all the specific >> stuff into a dedicated module and you import the shared modules. *Its >> not that hard :-) >> >> * * * * Cheers --- Jan > > Let's assume this situation I really can't find solution: > 1. a.pl is a shared module: > >:-module(a,[]). >:-export(tst). > > tst:- > foo. The normal declaration is as below. export is for some special cases. :- module(a, [tst/0]). tst :- foo. > 2. b.pl is: >:-module(b,[]). > >:-export(foo). > > foo:- > fail. > > It works if I consult both files and import 'a:tst' and 'b:foo' let's > say to dynamic module 'aa' and call aa:tst. (result is fail) > But when I'd like to have module 'bb' with shared predicate imported > from 'a:tst' redefined foo predicate from file c.pl: > 3. c.pl is: >:-module(c,[]). > >:-export(foo). > > foo:- > true. > > I consult c.pl and get error: > ERROR: Cannot import c:bob/0 into module user: already imported from b > > > When I tried to consult that files directly to module 'aa' or 'bb' I > have an error: > a:tst/0: Undefined procedure: a:foo/0 > ERROR: However, there are definitions for: > ERROR: aa:foo/0 > ERROR: b:foo/0 > > How do I have to modify my code to make it work? Because certainly I > don't know how to write call for 'foo' predicate in 'a' module to make > it redifinable and how to load module files? > By use_module, consult, import? Hmm. The problem is (if I understand you correcly; I'm not 100% sure about that) you want to create two different combinations in the user module. That of course won't work. This kind of unification of modules where the unified modules call each other in different combinations is not that simple. It is more the domain of OO skins like Logtalk. I once wrote a very simple-minded mini OO system by tricking the module system. You can find it here: http://gollem.science.uva.nl/git/tri...b74016223ff4dd If you download the project, you can see how it is used. --- Jan |
|
#5
| |||
| |||
| On 11 Wrz, 13:45, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote: > On 2008-09-11, Pawel Mitka <pmi...@gmail.com> wrote: > > > > > > > On 1 Sie, 11:49, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote: > >> On 2008-08-01,pmitka<pmi...@gmail.com> wrote: > > >> > I useprologas logic engine in my C++ application with MT. > >> > I put my dynamic predicates in thread local storage and it works with > >> > 'thread_local' property. Now I want to have different sets of non- > >> > dynamic predicates ( sometimes even different implementations of the > >> > same predicates) in different running threads ofprologengine. Is > >> > there any way to do this? > > >> > Documentation sais that thread_local are implicitly dynamic > >> > predicates. Unless I misunderstood it... > > >> Yip, and it cannot be static: new threads start without clauses for > >> the thread local predicates and and the end of the thread all clauses > >> are deleted. > > >> > Is there any property that would make static predicates thread_local? > > >> No. *I guess in theory this would be possible. > > >> > I figured out that I might use modules to workaround this situation. > >> > In this case I'd have separate module for each thread and import each > >> > predicate I want to this module. Is this correct approach? Although > >> > I'd prefer something cleaner/more simplistic... > > >> That is the right approach. *You put all the shared stuff in one or > >> more modules. *For each different context you load all the specific > >> stuff into a dedicated module and you import the shared modules. *Its > >> not that hard :-) > > >> * * * * Cheers --- Jan > > > Let's assume this situation I really can't find solution: > > 1. a.pl is a shared module: > > >:-module(a,[]). > >:-export(tst). > > > tst:- > > *foo. > > The normal declaration is as below. *export is for some special cases. > > :- module(a, [tst/0]). > > tst :- > * * foo. > > I used this way but in some tests I've changed to exports... > > > > > 2. b.pl is: > >:-module(b,[]). > > >:-export(foo). > > > foo:- > > * *fail. > > > It works if I consult both files and import 'a:tst' and 'b:foo' let's > > say to dynamic module 'aa' and call aa:tst. (result is fail) > > But when I'd like to have module 'bb' with shared predicate imported > > from 'a:tst' redefined foo predicate from file c.pl: > > 3. c.pl is: > >:-module(c,[]). > > >:-export(foo). > > > foo:- > > * *true. > > > I consult c.pl and get error: > > ERROR: Cannot import c:bob/0 into module user: already imported from b > > > When I tried to consult that files directly to module 'aa' or 'bb' I > > have an error: > > a:tst/0: Undefined procedure: a:foo/0 > > ERROR: * * However, there are definitions for: > > ERROR: * * * * aa:foo/0 > > ERROR: * * * * b:foo/0 > > > How do I have to modify my code to make it work? Because certainly I > > don't know how to write call for 'foo' predicate in 'a' module to make > > it redifinable and how to load module files? > > By use_module, consult, import? > > Hmm. *The problem is (if I understand you correcly; I'm not 100% sure > about that) you want to create two different combinations in the user > module. *That of course won't work. > I don't wan't to load it all to user module if it's possible. I wan't ot have 2 separate modules where I'd have 2 separate definitions of the same predicate 'foo' used by predicate 'tst' in separate dynamic modules: 1. a.pl + b.pl 2. a.pl + c.pl I wasn't able to find way to make it work correctly. > This kind of unification of modules where the unified modules call > each other in different combinations is not that simple. *It is more > the domain of OO skins like Logtalk. > > I once wrote a very simple-minded mini OO system by tricking the > module system. *You can find it here: > > http://gollem.science.uva.nl/git/tri...src/particle.p.... > > If you download the project, you can see how it is used. > > * * * * --- Jan- Ukryj cytowany tekst - > > - Pokaż cytowany tekst -- Ukryj cytowany tekst - > > - Pokaż cytowany tekst - |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.