I think [EMAIL PROTECTED] wrote:
> 
> would like to ask a related question about something that is still very
> unclear to me: if multiple threads are calling run(), what happens? say a
> bunch of threads invoke run() on the same Rete object in the following
> order:
> 
>   thread 1 ->rete.run()
>   thread 2 ->rete.run()
>   thread 3 ->rete.run()
>   ....
>   thread N ->rete.run()
> 
> could this result in an illegal system state if any of the run() calls
> overlap? could this crash Rete, or cause unexpected exceptions, etc.?
> 

First: nothing bad can happen, guaranteed. There is a single mutex
that protects run(), run(int), and runUntilHalt() such that each
engine can only be running in one thread at a time. Other threads can
be simultaneously adding/removing facts, so they can be influencing
the agenda during the run.

As to the order in which the various threads would enter the run()
method: I'm actually not sure that the Java Language Spec requires
them to proceed in order -- i.e., just because they call run() in the
order 1, 2, 3 doesn't mean they'll get the lock in that
order. One common practice is to call runUntilHalt()in a dedicated
thread, so that the engine is always running; when there's no work to
do, it sleeps.

This was brought up recently here on this list; see
http://www.mail-archive.com/[email protected]/msg04691.html  for
more information.


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

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