Module Thread_pool

module Thread_pool: Thread_pool

type t 
val invariant : t -> unit
val create : max_num_threads:int -> t Core.Std.Or_error.t
create ~max_num_threads returns a new thread pool. It is an error if max_num_threads < 1.
val finished_with : t -> unit Core.Std.Or_error.t
finished_with t destroys all the threads in t, and makes t no longer usable.

It is an error to call finished_with if the thread pool has unfinished work or unfinished helper threads. It is an error to call any other operation on t after calling finished_with t.

val max_num_threads : t -> int
max_num_threads t returns the maximum number of threads that t is allowed to create.
val num_threads : t -> int
num_threads t returns the number of threads that the pool t has created.
module Work_group: sig .. end
val create_work_group : ?min_assignable_threads:int ->
?max_assigned_threads:int ->
t -> Work_group.t Core.Std.Or_error.t
create_work_group t ~min_assignable_threads ~max_assigned_threads creates a new work group.

The thread pool does not internally refer to the Work_group.t it returns. So, it is OK for client code to use a finalizer to detect it becoming unused.

It is an error if any of the following are true:


val add_work_for_group : ?name:string ->
t ->
Work_group.t -> (unit -> unit) -> unit Core.Std.Or_error.t
add_work_for_group t work_group f enqueues f to be done by some thread in the pool, subject to the thread-usage limits of work_group.

It is an error to call add_work_for_group t work_group after having called finished_with_work_group t work_group.

val finished_with_work_group : t -> Work_group.t -> unit Core.Std.Or_error.t
finished_with_work_group t work_group informs thread pool t that the work_group will no longer be used.

It is an error to call finished_with_work_group work_group if work_group has unfinished work or has helper_threads for which finished_with_helper_thread hasn't yet been called.

module Helper_thread: sig .. end
val create_helper_thread : ?name:string ->
t ->
Work_group.t -> Helper_thread.t Core.Std.Or_error.t
create_helper_thread ?name t work_group creates a new helper thread that is part of work_group, i.e. until finished_with_helper_thread is called, the helper thread counts as one of the threads assigned to the work_group.

The thread pool does not internally refer to the Helper_thread.t it returns. So, it is OK for client code to use a finalizer to detect it becoming unused.

It is an error if no threads are available.

val add_work_for_helper_thread : ?name:string ->
t ->
Helper_thread.t -> (unit -> unit) -> unit Core.Std.Or_error.t
add_work_for_helper_thread t f enqueues f on helper thread t's work queue.

It is an error to call add_work_for_helper_thread t after finished_with_helper_thread t.

val finished_with_helper_thread : t -> Helper_thread.t -> unit Core.Std.Or_error.t
finished_with_helper_thread t helper_thread returns the helper thread to the general thread pool.

It is an error to call finished_with_helper_thread if the helper thread has unfinished work.

val sexp_of_t : t -> Sexplib.Sexp.t