[Haskell-cafe] Need a concurrency advice
heringtonlacey at mindspring.com
Mon Aug 22 23:36:34 EDT 2005
At 3:39 PM +0000 8/22/05, Dinh Tien Tuan Anh wrote:
>Basically, my program has 7 threads for 7 rules
>and they all use pattern-mattching (a rule MUST be evaluated by a thread)
>The problem is there are some overlapping rules, which match the
>same pattern and diifferent rules are likely to give different
>results (one rule might give a result, others might loop forever).
>Also, for a particular pattern, there's at least one matching rule
>and there may be some rule looping forever (try to evaluate a
>Im thinking of getting a list of all the applicable rules for a
>pattern, then hopefully can choose the best rule out of it. But we
>have no control over the scheduling of threads, so dont know when a
>thread finishs its evaluation (if it is applicable rule) or it just
>never terminates (rule that tries evaluating a _|_)
>So any ideas ?
If you can't choose a single best rule, you could start a thread on
each of the applicable rules and let them "race" each other. The
first to complete would provide the result and terminate its
"competitors". Concurrent Haskell
provides the facilities you'd need.
More information about the Haskell-Cafe