mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-05 19:00:33 -05:00
add start_thread_on_some_domain
This commit is contained in:
parent
5840ba0981
commit
d7220c75f5
2 changed files with 16 additions and 0 deletions
|
|
@ -69,8 +69,19 @@ module D_pool_ = struct
|
|||
let (lazy arr) = domains_ in
|
||||
assert (i < Array.length arr);
|
||||
S_queue.push arr.(i).q f
|
||||
|
||||
let run_on_and_wait (i : int) (f : unit -> 'a) : 'a =
|
||||
let q = S_queue.create () in
|
||||
run_on i (fun () ->
|
||||
let x = f () in
|
||||
S_queue.push q x);
|
||||
S_queue.pop q
|
||||
end
|
||||
|
||||
let start_thread_on_some_domain f x =
|
||||
let did = Random.int (D_pool_.n_domains ()) in
|
||||
D_pool_.run_on_and_wait did (fun () -> Thread.create f x)
|
||||
|
||||
module Pool = struct
|
||||
(* TODO: use a better queue for the tasks *)
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ module Pool : sig
|
|||
in one of the threads. *)
|
||||
end
|
||||
|
||||
val start_thread_on_some_domain : ('a -> unit) -> 'a -> Thread.t
|
||||
(** Similar to {!Thread.create}, but it picks a background domain at random
|
||||
to run the thread. This ensures that we don't always pick the same domain
|
||||
to run all the various threads needed in an application (timers, event loops, etc.) *)
|
||||
|
||||
(** Futures *)
|
||||
module Fut : sig
|
||||
type 'a t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue