Yes. It's a bit, er, indirect, but it would work, as the Order procedure is constantly being utilized during search. Though, the proposed Search.oz mods seem a little more straightforward. ;)
-- Harmon -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Luis Quesada Sent: Thursday, February 02, 2006 10:51 AM To: [EMAIL PROTECTED] Subject: Re: Race condition in Search.ozf Harmon Nine wrote: >So the program would look something like this? > >========================== >Sobj = {New Search.object script(Space OptProc)} > >proc {WillContinue NextSolution} {SObj next(NextSolution)} end >proc {WillStop NextSolution} NextSolution = stopped end > >P = {NewCell WillContinue} > >Thread 1: >proc {GetNextSolution} > NextSolution > in > [EMAIL PROTECTED] NextSolution} > > if NextSolution == stopped then > skip > else > Process NextSolution > {GetNextSolution} > end > >end > >Thread 2: >proc {StopThread} > P := WillStop > {Sobj stop} >end >========================== > > > What I mean is to redifine the Order that is passed as a paramenter to the script method: P={NewCell "your order procedure"} Order= proc{$ Old New} [EMAIL PROTECTED] Old New} end Sobj={New Search.object script(Script Order)} Thread 1: proc {GetNextSolution} NextSolution in {Sobj next(NextSolution)} if {Member NextSolution [stopped nil]} then skip else Process NextSolution {GetNextSolution} end end Thread 2: proc {Stop} P:=proc {$ _ _} fail end {Sobj stop} end >This is a better solution, i.e. it is deterministic in that the call in >Thread 2 to the StopThread proc is guaranteed to (eventually) stop >calculation. However there's still a race that has a (very small) >chance of causing the calculations not to stop immediately when the >"stop" method is called on SObj. An immediate termination would be >necessary on receipt of a user input event, or the expiration of a >soft-real-time timer. > >Scenario: >@P has value WillContinue >In Thread 1 (top of GetNextSolution proc), @P is dereferenced and thus >WillContinue is called. >Program execution in Thread 1 is now in the WillContinue proc, but >Thread 1 is pre-empted *before* the {SObj next(NextSolution}} call. > >Thread 2 fires up on user input event, changes the value of P to >WillStop and calls the stop method on SObj. >This call to the stop method sets the 'isStopped' flag for the Search >object SObj. >Thread 2 is pre-empted. > > If Stop has been executed before {Sobj next(NextSolution)}, {Sobj next(NextSolution)} will return immediately because of the failure exception. Luis ________________________________________________________________________ _________ mozart-hackers mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-hackers _________________________________________________________________________________ mozart-hackers mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-hackers
