summaryrefslogtreecommitdiff
path: root/testsuite/tests/lazy/lazy5.ml
blob: 4a8ac59fff7a1f9a5f5058044758599d1fc5a4a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(* TEST
 ocamlopt_flags += " -O3 ";
*)
let rec safe_force l =
  try Lazy.force l with
  | Lazy.Undefined ->
      Domain.cpu_relax ();
      safe_force l

let f count =
  let _n = (Domain.self ():> int) in
  let r = ref 0 in
  for i = 1 to count do
    incr r;
  done;
  !r

let l = lazy (f 1_000_000_000)
let d1 =
  Domain.spawn (fun () ->
      let _n = (Domain.self ():> int) in
      safe_force l)
let n2 = safe_force l
let n1 = Domain.join d1

let _ = Printf.printf "n1=%d n2=%d\n" n1 n2