Source

mutated_ocaml / testsuite / tests / lib-systhreads / testfork.ml

(* POSIX threads and fork() *)

let compute_thread c = ignore c
(*
  while true do
    print_char c; flush stdout;
    for i = 1 to 100000 do ignore(ref []) done
  done
*)

let main () =
  ignore(Thread.create compute_thread '1');
  Thread.delay 1.0;
  print_string "Forking..."; print_newline();
  match Unix.fork() with
  | 0 ->
      Thread.delay 0.5;
      print_string "In child..."; print_newline();
      Gc.minor();
      print_string "Child did minor GC."; print_newline();
      ignore(Thread.create compute_thread '2');
      Thread.delay 1.0;
      print_string "Child is exiting."; print_newline();
      exit 0
  | pid ->
      print_string "In parent..."; print_newline();
      Thread.delay 4.0;
      print_string "Parent is exiting."; print_newline();
      exit 0

let _ = main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.