Hi all,
I have not found a clean way to terminate IOzSeF search after a certain
time limit (it is sufficient for me that the search script makes regular
checks), it seems that the library does not provide a "killer" proc.
like the Search module. I created a workaround that seems to work that
uses Thread.terminate instead of the killer procedure, but it was a bit
of a trial/error (e.g. it does not work properly without
Thread.terminate being called in TimeCheck), so I wonder if there is a
better way of doing this.
Cheers,
Filip
------------------------------------------------------
The code:
LimitTime={Time.time}+MAX_SOLVE_TIME
fun {Solve Spec}
fun {SearchScript Spec KillServerPort}
proc {$ Root}
proc {TimeCheck}
if {Time.time}>LimitTime then
{Port.send KillServerPort false}
{Thread.terminate {Thread.this}}
end
end
in
...
{TimeCheck}
...
end
end
SearchResult
SearchOK
in
SearchResult=
thread
R %% Search result
KillServerPortStream
KillServerPort={NewPort KillServerPortStream}
T %% Search thread
in
%% Killer server
thread
case KillServerPortStream
of Val|_ then
SearchOK=Val
if Val==false then
{Thread.terminate T}
end
end
end
R=thread
T={Thread.this}
{IOzSeF.searchOne
{SearchScript Spec KillServerPort}}
end
{Wait R}
{Port.send KillServerPort true}
R
end
if {Not SearchOK} then SearchResult=nil end
case SearchResult
of Solution|_ then
...
else
...
end
end
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users