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