Open kayceesrk opened 9 years ago
I have a simple workaround.
we could have an ensure reagent : 'a casref -> ('a -> bool) -> ('b, 'b) reagent
that is basically a noop except that:
While deeply changing the internals might still be a good idea, because it might simplify some things, I think this is an interesting reagent anyway. And it could be use as a fix for the channels.
Or why not a "read and freeze" reagent (of type 'a casref -> (unit, 'a) reagent
)?
That one would read a reference while adding the same CAS that don't change the value to the reaction.
I like it. :+1: It sounds very similar to STM read log behavior. Essentially, you read a transaction variable and commit only if the variable hasn't changed.
The interesting question is what happens when there is non-detectable changes. Support there is a reference r
which happens to have a value v
. With read and freeze, you'd add a cas r v v
to the reaction. Concurrently, if two different reagents concurrently changes r
from v --> x
and then from x --> v
again, should we care about the fact that value changed? Is this change benign?
STMs typically consider this change to be malign; they'd use a version number to track changes to the reference. Thoughts?
As the whole kCAS system on which are built the reactions (an thus the reagent) does not take that kind of change into account anyway, I would tend to think we can consider them as benign...
swap
is racy. Inall_messages (MSQueue.snapshot e.incoming) >+> Reagent.send push_message
[1], channel state can change between checking for pending offers inall_messages
and posting a new message.[1] https://github.com/theolaurent/ocaml-reagent/blob/master/communication/Channel.ml#L49