Title: RE: JESS: Rule firing twice

On a related subject, if I have a multi-threaded program in which one thread modifies facts in real time according to some external events and another thread call run() on the engine periodically, do I have to synchronize the two threads so that no facts are modified when the engine is inside run()? Thanks.

Regards,

Shan Ming Woo


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 02, 2005 6:17 AM
To: jess-users@sandia.gov
Subject: Re: JESS: Rule firing twice

I went back and looked over your first message and this time paid
attention to the deffunction canBeginProcessing. Holy corrupted data
structures, Batman! You can't modify a fact on the *left* side of a
rule! The Rete network is *not* re-entrant, which is why it's
carefully protected against interference from other threads. But that
protection doesn't help if a predicate function changes the object
it's working on, sending a PropertyChangeEvent which modifies the fact
that's being pattern-matched!

This is something like writing a Java equals() method that changes the
object and its hashCode() when you call it. Try to store such an
object in a HashMap!

Change canBeginProcessing to be a pure predicate function; call
setProcessedEntity (and beginProcessing) on the *right* side of the
rule, after you've made this decision.


(deffunction canBeginProcessing(?station)
 (if (and (neq ?station nil)) then
     ;; Get the entity that can be processed.
     (bind ?entity (call ?station beginProcessing))
     ;; Assign the entity to the current station.
     (call ?station setProcessedEntity ?entity)
     ;; Return true if there is an entity.
     (return (neq ?entity nil))
 else
     (return FALSE)))


I think Nicolas Fortin wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Dr. Friedman-Hill,
>
> I've been curious and I've had another idea. Just before to call the
> Rete.run() method in my Java program, I have checked the agenda activations.
> It has strengthened my doubt about something wrong, since for the
> troublesome rule (process-entity), there are two activations with the same
> facts :
>
> PROCESS:
> [Activation: PROCESS::process-entity  f-15, f-42 ; time=45 ; salience=0]
> [Activation: PROCESS::process-entity  f-15, f-42 ; time=45 ; salience=0]
> STATUS:
> For a total of 7 activations in all modules.
>
> Is it really abnormal ?
>
> Thanks in advance,
>
> Nicolas
>
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
>



---------------------------------------------------------
Ernest Friedman-Hill 
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
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]
--------------------------------------------------------------------



-------------------------------------------------------------
Additional information is available upon request
Copyright (c) 2005 CLSA Asia-Pacific Markets. The information and statistical data herein have been obtained from sources we believe to be reliable but in no way are warranted by us as to accuracy or completeness. We do not undertake to advise you as to any change of our views. This is not a solicitation or any offer to buy or sell. CLSA Asia-Pacific Markets has produced this information for private circulation only. All information and advice is given in good faith but without any warranty.

CLSA Asia-Pacific Markets, its affiliates or companies or individuals connected with CLSA Asia-Pacific Markets may have used the information set forth herein before publication and may have positions in, may from time to time purchase or sell or may be materially interested in any of the securities mentioned or related securities. This information is subject to the terms and conditions of use set forth on the www.clsa.com website.

Any disclosure(s) in this report, for the purpose of paragraph 16 of the HK SFC Code of Conduct, only reflect(s) the position(s) of the CLSA B.V. Group but do(es) not include the position(s) of Calyon and/or its affiliates. MITA (P) 105/12/2004. V.050101.

This email is only for the use of the addressee and may contain information which is confidential, privileged or subject to copyright. If you receive this and are not the addressee, please contact the sender or [EMAIL PROTECTED] immediately. Thank you.

CLSA ASIA-PACIFIC MARKETS http://www.clsa.com

Reply via email to