Replies: 2 comments 3 replies
-
I'm not the author of picos, but in my understanding a `Computation.t`
is like a regular promise. It represents something that's running, and
has the moral equivalent of 3 states (running/done/canceled with
exception).
A trigger is more like a single-use callback in lwt (you need one
trigger per `Lwt.on_termination`, more or less) that is as lightweight
as possible. Unlike the callback, you can detach it if you don't need it
anymore, and it's thread safe. You can attach a trigger to a computation
but you can't attach a computation to another computation.
So I'd compare computation to `'a Lwt.t`, and triggers to reified
callbacks in Lwt (which you might want to use instead of adding more
promises and rely on `>>=`, for lower level control). They're distinct
because trigger will hopefully use only 2 small initial allocations, and
consume 2 words only once signaled.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
As far as I understand it, yes, trigger is fundamental and that's why it
lives in the core module :-).
For a MVar (a thread-safe box with 0 or 1 element, correct?) you would
probably use some sort of synchronization primitive and use a trigger in
the cases where you need to `await` (eg when `put`-ing an element into a
currently-full MVar). Each caller gets its own trigger.
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to get to the core building blocks of picos, and teasing out the fundamental primitives from the ones that are necessary to get around the idiosyncrasies of the programming language and the compiler. My aim is to formalise the core of picos, and formally specify (and potentially automatically verify) the contracts between picos, picos-compatible schedulers and concurrency libraries implementated on top of picos.
From first look, trigger and computation both look awfully similar. Both have an "unresolved" and "resolved" states, allow users to move them from "unresolved" to "resolved" states and allow users to block wait (await) on them for the states to move from "unresolved" to "resolved" states. Computation is more expressive in that it allows triggers to be attached and detached to it.
Is
Computation
the core primitive with whichTrigger
can be implemented? Why have both?Beta Was this translation helpful? Give feedback.
All reactions