Previously if we hit an error (last_exn being set) then we exited the
loop immediately and re-raised the exception. However this means jobs
which are still running would continue to run after goals exited.
Move the wait code outside the loop to ensure we always wait for jobs
to complete even in the error case.
let rec loop () =
if !last_exn = None then (
match next_job () with
- | Complete ->
- if !running > 0 then (
- Cmdline.debug "%d/%d threads running, waiting for completion"
- !running (Cmdline.nr_jobs ());
- Condition.wait cond lock;
- loop ()
- )
+ | Complete -> ()
| Not_ready ->
assert (!running > 0);
Cmdline.debug "%d/%d threads running, waiting for dependencies"
in
Mutex.lock lock;
loop ();
+
+ (* Wait for all jobs to complete. *)
+ while !running > 0 do
+ Cmdline.debug "%d/%d threads running, waiting for completion"
+ !running (Cmdline.nr_jobs ());
+ Condition.wait cond lock
+ done;
+
let exn = !last_exn in
Mutex.unlock lock;