Hi people,
here again with more problems.
Look at this small program:
**************************************
:- concurrent proceed/2.
:- use_module(library(concurrency)). :- use_module(library(system)). :- use_module(library(random)).
not(X) :- X,!,fail. not(X).
repeat. repeat :- repeat.
producer(N,0) :- display(end(N)),nl. producer(N,M) :- repeat, random(1,100,I), not(proceed(N,I)), <==== ???? display(proceed(N,I)), nl, asserta_fact(proceed(N,I)), M2 is M - 1, producer(N,M2).
start(0). start(N) :- eng_call(producer(N,5),create,create), M is N - 1, start(M).
*****************************************
This program starts N threads. Each thread calculates a random number. Then, if there is already a fact with this number fails and tries to recalculate another one. If not, asserts a fact with the number and the thread identifier. Each thread repeats this operation 5 times.
If I run this program as it is, it doesn't work. The strange thing is that when I remove the marked line (<==== ????) then it works!!!
Do you experiment the same behaviour? Anybody knows what's wrong?
I'm using Ciao1.5p166 and Linux.
Thanks in advance.
______________________________________________________________________________
_/ _/ _/_| Jordi Sabater Mir / _/ _/ _| IIIA - Institut d'Investigacio en Intel.ligencia Artificial _/ _/___| CSIC - Spanish Scientific Research Council _/ _/____| Campus Universitat Autonoma de Barcelona / _/ _| 08193 Bellaterra, Catalonia, Spain Ph.: +34 3 5809570 Fax.: +34 3 5809661 jsabater(a)iiia.csic.es http://www.iiia.csic.es ______________________________________________________________________________
First of all, predicates
not(X) :- X,!,fail. not(X).
repeat. repeat :- repeat.
are predefined in Ciao (not/1 is called (+)/1 (it is a prefix operator)). The problem in your program is that a call to a concurrent data predicate that has not been closed blocks (rather than failing) when there are no (more) clauses, waiting for more clauses to be asserted by other threads. To avoid that, use current_fact_nb/1, for example in your program try
+ current_fact_nb(proceed(N,I)),
Daniel Cabeza
I've been trying what you propose but it has the same behaviour. Now the program is:
**********************************************
:- concurrent proceed/2.
:- use_module(library(system)). :- use_module(library(random)).
producer(N,0) :- display(end(N)),nl. producer(N,M) :- repeat, random(1,100,I), + current_fact_nb(proceed(N,I)), display(proceed(N,I)), nl, asserta_fact(proceed(N,I)), M2 is M - 1, producer(N,M2).
start(0). start(N) :- eng_call(producer(N,5),create,create), M is N - 1, start(M).
********************************************
Again only prints two "proceed(X,Y)" and then stops.
______________________________________________________________________________
_/ _/ _/_| Jordi Sabater Mir / _/ _/ _| IIIA - Institut d'Investigacio en Intel.ligencia Artificial _/ _/___| CSIC - Spanish Scientific Research Council _/ _/____| Campus Universitat Autonoma de Barcelona / _/ _| 08193 Bellaterra, Catalonia, Spain Ph.: +34 3 5809570 Fax.: +34 3 5809661 jsabater(a)iiia.csic.es http://www.iiia.csic.es ______________________________________________________________________________