(** * A simple thread + fork test. Compile as: * ocamlopt.opt -threads -o threadTest unix.cmxa threads.cmxa threadTest.ml *) let () = (* Create a thread to join *) let t = Thread.create (fun x -> ()) () in Printf.printf "Thread created.\n"; flush stdout; (* Fork a new process *) match Unix.fork () with | 0 -> (* Join the thread in the child process and exit *) Printf.printf "Child process created.\n"; flush stdout; Thread.join t; Printf.printf "Child joined thread.\n"; flush stdout; exit 0 | _ as pid -> (* Join the thread and the child in the parent process and exit *) Printf.printf "Parent process continuing.\n"; flush stdout; Thread.join t; Printf.printf "Parent joined thread.\nWaiting on child.\n"; flush stdout; let _ = Unix.waitpid [] pid in Printf.printf "Child joined. Exiting.\n"; exit 0