src/Pure/ML-Systems/polyml-interrupt-timeout.ML
author webertj
Fri, 27 Jan 2006 20:17:24 +0100
changeset 18814 1a904aebfef0
parent 18760 97aaecb84afe
child 21266 288a504c24d6
permissions -rw-r--r--
interrupt_timeout for Poly replaced by stub

(*  Title:      Pure/ML-Systems/polyml-interrupt-timeout.ML
    ID:         $Id$
    Author:     Tjark Weber, Makarius
    Copyright   2006

Bounded time execution (similar to SML/NJ's TimeLimit structure) for Poly/ML.
*)

(* FIXME: this code appears to disable signal handling in child databases altogether (?)
local

  val alarm_active = ref false;

  val _ = Signal.signal (Posix.Signal.alrm, Signal.SIG_HANDLE (fn _ =>
    let val active = ! alarm_active in
      alarm_active := false;
      if active then
        Process.interruptConsoleProcesses ()
      else
        ()
    end));

in

  fun interrupt_timeout time f x =
  let
    fun deactivate_alarm () = (
      alarm_active := false;
      Posix.Process.alarm Time.zeroTime
    )
  in
    alarm_active := true;
    Posix.Process.alarm time;
    let val result = f x in
      deactivate_alarm ();
      result
    end handle exn => (
      deactivate_alarm ();
      raise exn
    )
  end;

end;
*)

fun interrupt_timeout time f x =
  f x;