File: multithreading.ml

package info (click to toggle)
ocaml-luv 0.5.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 3,504 kB
  • sloc: ml: 11,130; makefile: 6,223; sh: 4,592; ansic: 1,517; python: 38
file content (17 lines) | stat: -rw-r--r-- 540 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(* Rather than testing timers, this test uses timers to test that Luv.Loop.run
   releases the runtime lock. So, in a sense, it is primarily a loop test. *)
let () =
  Helpers.with_timer @@ fun timer ->

  let start_time = Unix.gettimeofday () in

  Luv.Timer.start timer 200 ignore
  |> ok "start" @@ fun () ->

  ignore @@ Thread.create (fun () -> print_endline "Worker thread") ();

  print_endline "Main thread";
  Luv.Loop.run () |> ignore;
  let elapsed = Unix.gettimeofday () -. start_time in

  Printf.printf "%b\n" (elapsed < 0.5)