fix: Fork_join.for_ 0 must not hang

This commit is contained in:
Simon Cruanes 2023-07-13 12:23:25 -04:00
parent e6a2afb2ba
commit 20240a6190
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 46 additions and 40 deletions

View file

@ -92,6 +92,7 @@ let both f g : _ * _ =
let both_ignore f g = ignore (both f g : _ * _)
let for_ ?chunk_size n (f : int -> int -> unit) : unit =
if n > 0 then (
let has_failed = A.make false in
let missing = A.make n in
@ -136,8 +137,8 @@ let for_ ?chunk_size n (f : int -> int -> unit) : unit =
(fun ~run suspension ->
(* run tasks, then we'll resume [suspension] *)
start_tasks ~run suspension);
};
()
}
)
let all_array ?chunk_size (fs : _ array) : _ array =
let len = Array.length fs in

View file

@ -42,6 +42,11 @@ let () =
let exp_sum = List.init 42 (fun x -> x * x) |> List.fold_left ( + ) 0 in
assert (par_sum = exp_sum)
let () =
Pool.run_wait_block pool (fun () ->
Fork_join.for_ 0 (fun _ _ -> assert false));
()
let () =
let total_sum = Atomic.make 0 in