packages feed

alms-0.4.9: examples/threads2.alms

(* Another example with threads. *)

let printer : unit -> unit =
  let rec loop (_ : unit) : unit =
    Thread.delay 100000;
    putStr "x";
    flush ();
    loop ()
  in loop

let startStop : unit -> unit -o unit =
  fun _: unit ->
    let id = Thread.fork printer in
    let id = Thread.print id in
      fun _: unit ->
        Thread.kill id

let timer : unit -> unit =
  fun _: unit ->
    let stop = startStop () in
      Thread.delay 2000000;
      stop ()

in timer ()