Hi again,

I'm having a problem with threads right now. I use the following code:

(deffunction read-answer (?EVENT)
  (bind ?source (?EVENT getSource))
  (bind ?window (?source getTopLevelAncestor))
  (bind ?answer (?window getAnswer))
  (bind ?question (fetch QUESTION))
  (bind ?id (fact-slot-value ?vraag id))
  (assert (answer (id ?id) (text ?answer)))
  (?window dispose)
  (run))

(deffunction ask-question (?QUESTION)
  (store QUESTION ?QUESTION)
  (bind ?text (fact-slot-value ?QUESTION text))
  (bind ?listener (new jess.awt.ActionListener read-answer (engine)))
  (bind ?display (new Display ?text))
  (?display addActionListener ?listener)
  (halt))

The ask-question function will make a Display object, which is a 
subclass of a javax.swing.JFrame. This Display object asks the user a 
question. The execution of the rule engine has to stop until the user 
answered this question. No further activations are allowed to be 
executed. Now I use the halt function, but the problem is that this 
function not only stops the execution cycle, but also returns. 

Now in Java i have some code like:

Rete expert = new Rete();
expert.executeCommand("(batch expert.clp)");
expert.run();
expert.fetch("OUTPUT");

When the halt function is called, the Rete object returns TRUE and the 
Java code tries to fetch OUTPUT. The OUTPUT isnt there yet, of course. 
I only want Java to fetch OUTPUT when the Rete object has finished 
firing all of its activated rules. So what I need is a halt function 
that doesnt return. I cant use ((engine) waitForActivations) cause that 
function keeps firing the activated rules, which , in my case, will 
lead to an incorrect solution. The generated answer facts will cause 
certain assertions, needed by other modules: if the activations keep 
firing, those other modules will presume those other assertions arent 
there. This will cause the output to be wrong.

What is the best solution to this problem? I was trying to use a lock. 
The main thread would call wait() on it, while the event thread would 
call notify() on it when the answer fact was generated. But this didnt 
work.

Regards,
Steffen.

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to