(* main.sml *) structure Main :> MAIN = struct structure T = Threads (* val work : int -> unit *) fun work n = let fun f 0 = nil | f m = m :: f(m - 1) val m = n * 10000 in f m end (* val leaf : int -> unit *) fun child n = (T.print(Int.toString n ^ " starting\n"); work n; T.print(Int.toString n ^ " ending\n")) (* val main : unit -> unit *) fun main() = (T.spawn(fn () => child 0); T.spawn(fn () => child 1); T.spawn(fn () => child 2); T.spawn(fn () => child 3); T.spawn(fn () => child 4); T.spawn(fn () => child 5); T.spawn(fn () => child 6); T.spawn(fn () => child 7); T.spawn(fn () => child 8); T.spawn(fn () => child 9)) (* val doit : unit -> unit *) fun doit() = T.run main end;