(* main.sml *) (* main processing *) structure Main :> MAIN = struct open CML (* val print : string -> unit we must mention TextIO somewhere in our program, in order to get the correct version of print *) val print = TextIO.print (* val producer : string Buffer.buffer * string -> 'a *) fun producer(buf, name) = let (* val loop : int -> 'a *) fun loop n = (Buffer.add(buf, name ^ ":" ^ Int.toString n); loop(n + 1)) in loop 0 end (* val main : unit -> unit *) fun main() = let val buf : string Buffer.buffer = Buffer.make() (* val loop : unit -> unit *) fun loop() = case TextIO.inputLine TextIO.stdIn of SOME "\n" => (print(Buffer.del buf); print "\n"; loop()) | _ => RunCML.shutdown OS.Process.success in spawn(fn () => producer(buf, "first")); spawn(fn () => producer(buf, "second")); spawn(fn () => producer(buf, "third")); loop() end (* val doit : unit -> OS.Process.status the second parameter to RunCML.doit is the scheduling time slice; NONE means the default slice of 20 milliseconds *) fun doit() = RunCML.doit(main, NONE) end;