From b451fde8535a6a99dbbc9a3c862f64946453d122 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 15 Jun 2023 10:52:17 -0400 Subject: [PATCH] add `Pool.shutdown_without_waiting` --- src/pool.ml | 7 +++++-- src/pool.mli | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pool.ml b/src/pool.ml index 87257f7d..4f4abac3 100644 --- a/src/pool.ml +++ b/src/pool.ml @@ -178,9 +178,12 @@ let create ?(on_init_thread = default_thread_init_exit_) done; pool -let shutdown (self : t) : unit = +let shutdown_ ~wait (self : t) : unit = let was_active = A.exchange self.active false in (* close the job queues, which will fail future calls to [run], and wake up the subset of [self.threads] that are waiting on them. *) 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 diff --git a/src/pool.mli b/src/pool.mli index 3fc6c983..b11cf496 100644 --- a/src/pool.mli +++ b/src/pool.mli @@ -60,6 +60,10 @@ val num_tasks : t -> int val shutdown : t -> unit (** 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 val run : t -> (unit -> unit) -> unit