File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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(* */**)
8798val nbthreads : unit -> int
8899val nbthreadsbusy : unit -> int
89100val 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments