Race condition in Search.ozf
Harmon Nine
hnine at isis.vanderbilt.edu
Wed Feb 1 20:32:53 CET 2006
Actually, we tried an approach like this as well. Unfortunately, there
is still a race, as there is a chance, however small, that the stop
method could be called in between the checking of the 'stopped' flag and
the call to the "next" (or other) method in the Search.object subclass.
This approach decreases the probability that the "stop" will succeed,
but it's still not 100%, and thus still probabilistic.
Of course, the mods to make "stop" deterministic might break some
existing code. So it might be better to put it into a new class like
"SearchDet.oz". This is what we did for our project.
Regards,
-- Harmon
-----Original Message-----
From: hackers-bounces at mozart-oz.org
[mailto:hackers-bounces at mozart-oz.org] On Behalf Of Raphael Collet
Sent: Wednesday, February 01, 2006 9:36 AM
To: hackers at mozart-oz.org
Subject: Re: Race condition in Search.ozf
Yves Jaradin wrote:
> an alternate solution would be to first stop the loop in thread1 and
> then to stop the (possibly running) search. (See code below)
> To avoid a potential race-condition (thread1 at position (2) when
> StopCalc is called), the stopping is retried until confirmed.
> Cells could be used if you want to resume the computation later.
There is a much clearer solution. Just extend Search.object, redefine
stop(), and provides an explicit reset() method:
local
SearchObject = Search.object
in
class BetterSearchObject from SearchObject
attr stopped: false
meth next($)
if @stopped then stopped else SearchObject,next($) end
end
meth nextS($)
if @stopped then stopped else SearchObject,nextS($) end
end
meth nextP($)
if @stopped then stopped else SearchObject,nextP($) end
end
meth last($)
if @stopped then stopped else SearchObject,last($) end
end
meth lastS($)
if @stopped then stopped else SearchObject,lastS($) end
end
meth lastP($)
if @stopped then stopped else SearchObject,lastP($) end
end
meth stop
stopped := true SearchObject,stop
end
meth reset
stopped := false
end
end
end
Cheers,
raph
________________________________________________________________________
_________
mozart-hackers mailing list
mozart-hackers at ps.uni-sb.de
http://www.mozart-oz.org/mailman/listinfo/mozart-hackers
More information about the mozart-hackers
mailing list