Hi Julio,

Look, your example does not work because if the element is in both lists
both threads are going to try and determine A, which will necessarily
fail.
Also nobody ever binds A to some value indicating the element is not in
either list.

Here is a version of something similar that would work:

------------------------
proc {TheFirstWins Tasks Rslt Success}
   Rslts
   RsltPort = {NewPort Rslts}
   AllFinished = {FoldL Tasks
                  proc {$ PrevFinished Task ImFinished}
                     TaskThread
                  in
                     thread
                        TaskThread = {Thread.this}
                        try
                           MyRslt = {Task}
                        in
                           if {Not {IsFree MyRslt}} then
                              {Send RsltPort MyRslt}
                              {Wait Rslts} % : just in case
                           end
                        catch X then
                           {Send RsltPort {Value.failed X}}
                           {Wait Rslts}
                        end
                        PrevFinished = ImFinished
                        {Wait _}
                     end
                     thread % thread killer:
                        {Wait Rslts}
                        {Thread.terminate TaskThread}
                     end
                  end
                  unit}
in
   {Record.waitOr Rslts#AllFinished _}
   Success = {Not {IsFree Rslts}}
   if Success then Rslt = Rslts.1 else
      {Send RsltPort unit} % enables thread-killing
   end
end
--------------

I haven't tested it, but conceptually it must be ok. Tasks here is a list
of unary procedures, which could look like:

[ fun {$} {Esta E L1 $ 1} end
  fun {$} {Esta E L2 $ 2} end
]

I also included some sort of exception handling.

Cheers,

Jorge.

[EMAIL PROTECTED] escreveu:
> Hello
>
> An example I think for my students. A concurrent search for an element
in two lists
>
> declare
> proc {Esta E L ?A Id}
>     case L
>     of nil then skip
>     []X|Xs then if X==E then A=Id#true else {Esta E Xs ?A Id} end end
> end
>
> proc {Esta2 E L1 L2 ?A}
>     thread {Esta E L1 ?A 1} end
>     thread {Esta E L2 ?A 2} end
> end
> declare
> Ls1= [1 3 5 7 9 11 13 15]
> Ls2= [2 4 6 8 10 12 14 16 18]
> R={Esta2 13 Ls1 Ls2} {Browse R}
>
> It seems works.  It's a good example?  The question is: When one of the
threads binds ?A, the others threads continue making the search. How can
one stop the others threads to continue working?
>
>
> Thanks (apologize for my english)
>
> Julio H Vargas
>
> ---------------------------------------------------------------- This
message was sent using IMP, the Internet Messaging Program.
>
>
>
> _________________________________________
> Universidad Tecnológica de Pereira
> _________________________________________________________________________________
mozart-users mailing list
> [email protected]
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>


Jorge M. Pelizzoni
ICMC - Universidade de São Paulo

call me at http://www.jaxtr.com/jpeliz




_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to