add Pool.shutdown_without_waiting

This commit is contained in:
Simon Cruanes 2023-06-15 10:52:17 -04:00
parent 059ee8a1d5
commit b451fde853
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 9 additions and 2 deletions

View file

@ -178,9 +178,12 @@ let create ?(on_init_thread = default_thread_init_exit_)
done; done;
pool pool
let shutdown (self : t) : unit = let shutdown_ ~wait (self : t) : unit =
let was_active = A.exchange self.active false in let was_active = A.exchange self.active false in
(* close the job queues, which will fail future calls to [run], (* close the job queues, which will fail future calls to [run],
and wake up the subset of [self.threads] that are waiting on them. *) and wake up the subset of [self.threads] that are waiting on them. *)
if was_active then Array.iter Bb_queue.close self.qs; if was_active then Array.iter Bb_queue.close self.qs;
Array.iter Thread.join self.threads if wait then Array.iter Thread.join self.threads
let shutdown_without_waiting (self : t) : unit = shutdown_ self ~wait:false
let shutdown (self : t) : unit = shutdown_ self ~wait:true

View file

@ -60,6 +60,10 @@ val num_tasks : t -> int
val shutdown : t -> unit val shutdown : t -> unit
(** Shutdown the pool and wait for it to terminate. Idempotent. *) (** Shutdown the pool and wait for it to terminate. Idempotent. *)
val shutdown_without_waiting : t -> unit
(** Shutdown the pool, and do not wait for it to terminate. Idempotent.
@since 0.2 *)
exception Shutdown exception Shutdown
val run : t -> (unit -> unit) -> unit val run : t -> (unit -> unit) -> unit