-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use an integer has an identifier for fiber instead of ==
#115
Comments
Would the use of FLS be sufficient? module Picos_fiber_id : sig
val fiber_id : unit -> int
(** [fiber_id ()] returns a unique integer id for the current fiber. *)
end = struct
let fiber_id_key =
let next = Atomic.make 0 in
Fiber.FLS.new_key
@@ Computed (fun () ->
Atomic.fetch_and_add next 1)
let fiber_id () =
Fiber.FLS.get (Fiber.current ()) fiber_id_key
end We could put this into a library for Picos. |
My idea is precisely to have an independent This could be broken down into:
This would allow In this case, I'd like |
If I understand correctly what you are after then this is something I also thought about a lot while designing the Fiber concept. Yes, I agree, it would be nice to be able to leave the representation of the "per fiber state" abstract. I recall talking about this in some meetings. Unfortunately I am sceptical that any of the ways to do that (e.g. objects, modules, ... effects) would be better (faster, taking less memory, simpler, easier, ...) in practice than the current design (I suspect most other ways will be the opposite: slower, take more memory, more complicated, more difficult to work with or more difficult for a scheduler to provide). The idea with the current design is to define a "fiber" concept that should not be too costly for a scheduler to maintain as part of their per fiber state. Nothing prevents a scheduler from having more per fiber state. For example,
and the picos/lib/picos_threaded/picos_threaded.ml Lines 52 to 56 in 534944e
Would this not work in your case (i.e. define your own per fiber state record with Note that a Picos compatible scheduler should not only allow one to An advantage of having a concrete Integer ids are problematic. For example, I would much rather have Note that |
Concerning some parts of Picos, it's required to know which is our current fiber to compare with some others (like for mutex and condition). It requires that
Fiber
must be used to be able to useLazy
,Mutex
orCondition
. However, only a comparison is needed. To give an opportunity for someone else to implement its own fiber but be able to use these modules, it can be interesting to define an effect such astype _ Effect.t += Current : int Effect.t
which returns an unique identifier of the current fiber. By this way, the scheduler implementor just need to provide such unique identifier instead of aFiber.t
.The text was updated successfully, but these errors were encountered: