(* 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 sleep : int -> unit *) fun sleep n = sync(timeOutEvt(Time.fromSeconds n)) (* val consumer : string * int Multicast.mchan * int -> unit *) fun consumer(name, mCh, tim) = let val port = Multicast.port mCh val recvEvt = Multicast.recvEvt port (* val loop : unit -> unit *) fun loop() = (print(name ^ " : " ^ Int.toString(sync recvEvt) ^ "\n"); sleep tim; loop()) in loop() end (* val main : unit -> unit *) fun main() = let val mCh : int Multicast.mchan = Multicast.mChannel() (* val loop : int -> unit *) fun loop n = case TextIO.inputLine TextIO.stdIn of SOME "\n" => (Multicast.multicast(mCh, n); loop(n + 1)) | _ => RunCML.shutdown OS.Process.success in spawn(fn () => consumer("first", mCh, 2)); spawn(fn () => consumer("second", mCh, 5)); spawn(fn () => consumer("third", mCh, 7)); loop 0 end (* val doit : unit -> OS.Process.status *) fun doit() = RunCML.doit(main, NONE) end;