Replies: 3 comments
-
Thank you for the feedback! I hope that the discussion here will prove valuable. Briefly, I believe there might be some misunderstandings here and also I believe it might be possible to improve the Picos (default) implementation for the purpose(s) that it serves.
Yes, the I now see that we understand the concept of "default" implementation differently. What I consider the "default implementation" (at the time of writing this) is basically just the default.ml file. That file implements default versions of On OCaml 4 those default implementations are (at the time of writing this) just used rather directly to implement the Picos On OCaml 5 those default implementation are (at the time of writing this) used in case the corresponding effects Aside from the default.ml file, the rest of the code is what I consider (more or less) essential implementation of the Picos interface that allows concurrent programming libraries to link to it and use it to interact with schedulers via the
I'm not entirely sure what you mean by "provided only [...] type definitions [...] standard effects". Could you elaborate on that? What exactly would be provided? A plain Aside from the type signature, Picos proposal intentionally includes essential implementations of the core concepts ( I'll continue after having lunch. |
Beta Was this translation helpful? Give feedback.
-
Hmm... There seems to be some misunderstanding here. The default implementation of The fundamental idea behind the OCaml 4 compatible default implementations is to make it so that a fiber is equivalent to a (sys)thread (or, on OCaml 5, when threads are not available, to a domain). So, for example, the default The default implementation then stores information for the thread (or fiber) in thread-local storage. The per-thread information includes a mutex, a condition, and the fiber object. What the default At no point does The The default implementation of Addition: Note that the per-domain state is only initialized and the background thread is only started in case the default Addition: Ended up adding a section on Default behaviors to the documentation. |
Beta Was this translation helpful? Give feedback.
-
Now, I agree that the default implementation (using (sys)thread per fiber) is not what most serious multicore applications in OCaml 5 should be using. (Note that at this point I'm talking about the default implementation which is essentially in the default.ml file.) That is because a proper scheduler (by handling the effects) can provide fibers more efficiently. The intention behind the default behaviors is to allow libraries implemented in Picos to work out-of-the-box without a scheduler. Consider the following REPL interaction using Kcas (implemented in Picos): utop # open Kcas ;;
utop # open Kcas_data ;;
utop # open Picos ;;
utop # let fiber = Loc.make None ;;
val fiber : '_weak1 option Loc.t = <abstr>
utop # let queue = Queue.create () ;;
val queue : '_weak2 Kcas_data.Queue.t = <abstr>
utop # let domain = Domain.spawn (fun () ->
Loc.set fiber (Some (Fiber.current () :> Fiber.as_async));
Queue.take_blocking queue) ;;
val domain : '_weak2 Domain.t = <abstr>
utop # Option.get (Loc.get fiber) |> Fiber.computation |> fun (Computation.Packed computation) ->
Computation.cancel computation (Exn_bt.get_callstack 0 (Failure "I got you!")) ;;
- : unit = ()
utop # Domain.join domain ;;
Exception: Failure "I got you!". It all works! (The blocking take from a queue blocked the domain and we could even cancel the domain via Picos — normally such cancelation would happen indirectly through something else implemented in Picos like a structured concurrency mechanism.) The primary audience for this is casual users. Users who are not yet intimately familiar with concepts such as schedulers or even experienced users that just want to quickly try something. Without some sort of default implementation it becomes much more involved to use anything implemented in Picos. Something along the lines of:
I believe requiring the above will create a barrier to entry and adoption of libraries implemented in Picos. The default implementation avoids all that hassle at a fairly small cost: relatively small amount of code and tiny bit of overhead per effect invocation to handle the Now, I don't personally consider the amount of code the default implementation adds as Perhaps there is some other way to provide default implementations in a manner that requires opt-in, but allows that opt-in to be done conveniently even in a REPL environment. |
Beta Was this translation helpful? Give feedback.
-
Currently Picos has a default implementation of the whole interface for both OCaml 4 and OCaml 5. The linecount for that is 756 lines (as per sloccount).
I think the
.mli
interface is great and what it provides is a good basis for a common language between libraries. However trying to implement these on OCaml 4 with things likeawait
spawning a new thread is not going to be useful in practice1. I think it'd be a lot better if Picos provided only this:await
andspawn
andcancel_after
, implementation being left to the actual scheduler that will provide themand there could be a side library (say
picos.basic
orpicos-basic
orpicos-default
), totally optional, that would provide a basic implementation of all that with some simple scheduler that handles all the effects.This makes
picos
a lighter, less fussy dependency, so it's an easier choice to depend on it.Footnotes
I like threads, but while spawning a thread per request is mostly fine for some real use cases, spawning a thread per
await
when writing highly concurrent code based on fibers is going to have a really high overhead. ↩Beta Was this translation helpful? Give feedback.
All reactions