Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/src/smlnj-lib/Util/time-limit.sml
ViewVC logotype

View of /sml/trunk/src/smlnj-lib/Util/time-limit.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (download) (annotate)
Thu Jun 1 18:34:03 2000 UTC (19 years, 4 months ago) by monnier
File size: 793 byte(s)
bring revisions from the vendor branch to the trunk
(* time-limit.sml
 *
 * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.  See COPYRIGHT file for details.
 *)

structure TimeLimit : sig
    exception TimeOut
    val timeLimit : Time.time -> ('a -> 'b) -> 'a -> 'b
  end = struct

    exception TimeOut

    fun timeLimit t f x = let
	  val setitimer = SMLofNJ.IntervalTimer.setIntTimer
	  fun timerOn () = ignore(setitimer (SOME t))
	  fun timerOff () = ignore(setitimer NONE)
	  val escapeCont = SMLofNJ.Cont.callcc (fn k => (
		SMLofNJ.Cont.callcc (fn k' => (SMLofNJ.Cont.throw k k'));
		timerOff();
		raise TimeOut))
	  fun handler _ = escapeCont
	  in
	    Signals.setHandler (Signals.sigALRM, Signals.HANDLER handler);
	    timerOn();
	    ((f x) handle ex => (timerOff(); raise ex))
	      before timerOff()
	  end

  end; (* TimeLimit *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0