Skip to content

Commit 75ba144

Browse files
Lwt_preemptive better name for worker termination
1 parent f4aa151 commit 75ba144

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/unix/lwt_preemptive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,5 @@ let run_in_domain_dont_wait d f handler =
276276
let f () = Lwt.catch f (fun exc -> handler exc; Lwt.return_unit) in
277277
run_in_domain_dont_wait d f
278278

279-
let kill_all () =
279+
let terminate_worker_threads () =
280280
Queue.iter (fun thread -> CELL.kill thread.task_cell) (Domain.DLS.get workers)

src/unix/lwt_preemptive.mli

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@ val get_max_number_of_threads_queued : unit -> int
8383
(** Returns the size of the waiting queue, if no more threads are
8484
available *)
8585

86+
val terminate_worker_threads : unit -> unit
87+
(* [terminate_worker_threads ()] queues up a message for all the workers of the
88+
calling domain to self-terminate. This causes all the workers to terminate
89+
after their current jobs are done which causes the threads of these workers
90+
to end.
91+
92+
Terminating the threads attached to a domain is necessary for joining the
93+
domain. Thus, if you use-case for domains includes spawning and joining them,
94+
you must call [terminate_worker_threads] just before calling
95+
[Domain.join]. *)
96+
8697
(**/**)
8798
val nbthreads : unit -> int
8899
val nbthreadsbusy : unit -> int
89100
val nbthreadsqueued : unit -> int
90-
91-
(* kill_all is to be called before joining the domain, not satisfying UI for
92-
now, searching for a better way *)
93-
val kill_all : unit -> unit

test/multidomain/preempting.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let domain_go_brrrrrrr input = Domain.spawn (fun () ->
2121
Lwt_list.map_p (Lwt_preemptive.detach simulate_work) input
2222
)
2323
in
24-
Lwt_preemptive.kill_all ();
24+
Lwt_preemptive.terminate_worker_threads ();
2525
v
2626
)
2727

0 commit comments

Comments
 (0)