Guest User

Untitled

a guest
Mar 25th, 2013
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.41 KB | None | 0 0
  1. (* Why ii is not different from 0 ? *)
  2.  
  3. let ii = ref 0;;
  4.  
  5. let foo () =
  6.   for i=0 to 100000000 do
  7.     incr ii
  8.   done
  9. ;;
  10.  
  11. let bar () =
  12.   for i=0 to 3 do
  13.     match Unix.fork () with
  14.     | 0 ->
  15.         begin
  16.           foo ();
  17.           exit 0;
  18.         end
  19.     | -1 -> failwith "fork"
  20.     | _ -> ()
  21.   done;
  22.   for i=0 to 3 do ignore (Unix.wait ()) done;
  23.   print_endline (string_of_int !ii)
  24. ;;
  25.  
  26. bar ();;
Advertisement
Add Comment
Please, Sign In to add comment