(************************************************************ return_thread_value.ml Created : Tue Oct 7 13:19:08 2003 Last modified: Tue Oct 07 13:28:58 2003 Compile: ocamlc -thread unix.cma threads.cma return_thread_value.ml -o return_thread_value # FTP Directory: sources/ocaml # ************************************************************) (** @author Takashi Masuyama *) let future f x = (* 結果の書き込み先をローカルにする。 *) let result = ref [] in let t = Thread.create (fun x -> result := (f x)::!result) x in (t, result) ;; (* ううむ、なにか違う名前だったような.... *) let attach (t, result) = begin Thread.join t; match !result with hd::[] -> hd | _ -> failwith "???" end ;; let _ = let id = future (fun x -> "Mr. "^x) "mamewo" in print_endline "hoge"; print_endline (attach id)