summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib-channels/refcounting.ml
blob: bc0b8dfe66dbd8501025833d58b3821899d6faa9 (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
27
28
29
30
31
32
(* TEST
   * expect
*)

(* Test the behavior of channel refcounting. *)

(* out_channels_list is the only function that increases the number of reference
  to a channel in the standard library *)
external out_channels_list : unit -> out_channel list = "caml_ml_out_channels_list"

let duplicate_and_close () =
  let l = out_channels_list () in
  List.iter Stdlib.close_out l

let rec loop n () =
  if n <> 0 then
    begin
      duplicate_and_close ();
      loop (n-1) ()
    end


let dls = List.map Domain.spawn (List.init 4 (fun _ -> loop 100))
let () = List.iter Domain.join dls

[%%expect{|
external out_channels_list : unit -> out_channel list
  = "caml_ml_out_channels_list"
val duplicate_and_close : unit -> unit = <fun>
val loop : int -> unit -> unit = <fun>
val dls : unit Domain.t list = [<abstr>; <abstr>; <abstr>; <abstr>]
|}]