[MLton] interrupted system call

Matthew Fluet fluet@cs.cornell.edu
Mon, 22 Mar 2004 18:37:34 -0500 (EST)


Consider the following program:

structure Main =
   struct
      structure Signal = MLton.Signal
      structure Itimer = MLton.Itimer

      val alrmHandler = fn t => t
      fun setItimer t =
	 Itimer.set (Itimer.Real,
		     {value = t,
		      interval = t})
      fun setAlrmHandler h =
	 Signal.setHandler (Itimer.signal Itimer.Real, h)

      fun doit n =
	 let
	    val () = setAlrmHandler (Signal.Handler.handler alrmHandler)
	    val () = setItimer (Time.fromMilliseconds 10)

	    fun loop i =
	       if i > n
		  then OS.Process.exit OS.Process.success
		  else let
			  val i' = (Int.toString i) ^ "\n"
			  fun loop' j =
			     if j > i then ()
			     else (print i'
				   ; loop' (j + 1))
		       in
			  loop' 0
			  ; loop (i + 1)
		       end
	 in
	    loop 0
	 end
   end

val n =
   case CommandLine.arguments () of
      [] => 1000
    | n::_ => (case Int.fromString n of
		  NONE => 1000
		| SOME n => n)
val _ = Main.doit n


Running this program consistently raises an exception and exits (on
Linux):

...
172
172
unhandled exception: Io: output "<stdout>" failed with SysErr: Interrupted
system call [intr]
with history:
        <basis>/io/stream-io.fun 50.47

I'm confused as to why the system call is failing.  My reading of the
setitimer man pages suggests that the alrm signal isn't raised while in
the kernel.  If I comment out the  setItimer  call, then the program
completes without error.

Any thoughts?