Hi David,
On Monday 31 May 2004 18:03, David Matthews wrote:
I tried this on a number of platforms using PolyML 4.1.3 and haven't had any crash. Which version of Poly/ML are you running?
thanks for your quick reply. You are right; the segmentation fault apparently was caused not by PolyML (version 4.1.3 on x86-linux), but by a wrapper script that I was using.
Below is a version of my code that passes on any exception raised in f, just like the SML/NJ function TimeLimit.timeLimit does. Maybe it's useful for someone.
structure TimeLimit : sig exception TimeOut val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b end = struct
exception TimeOut
fun timeLimit t f x = let datatype ('a, 'b) union = INL of 'a | INR of 'b val result = Process.channel () fun workerThread () = Process.send (result, SOME (INL (f x) handle exn => INR exn)) val interrupt = Process.console workerThread val old_handle = Signal.signal (Posix.Signal.alrm, Signal.SIG_HANDLE (fn _ => (interrupt (); Process.send (result, NONE)))) in Posix.Process.alarm t; case Process.receive result of SOME (INL fx) => (Posix.Process.alarm Time.zeroTime; Signal.signal (Posix.Signal.alrm, old_handle); fx) | SOME (INR exn) => (Posix.Process.alarm Time.zeroTime; Signal.signal (Posix.Signal.alrm, old_handle); raise exn) | NONE => (Signal.signal (Posix.Signal.alrm, old_handle); raise TimeOut) end
end;
Regards, Tjark