-
Notifications
You must be signed in to change notification settings - Fork 529
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
AtomicCell#get
should not semantically block
#3518
AtomicCell#get
should not semantically block
#3518
Conversation
Conceptually I agree, however I still think it would be best to have both options (and I personally think My rationale is that the point of |
I think one way to frame the semantics question is: what happens to the value of the cell during a modification? Does it retain its current value until updated, or is it in some "indeterminate value" state? If we say its "indeterminate" during modification, then I guess we can keep |
Well, another way to think about it, is that since an The question then is, something like |
Writing is certainly exclusive, but not sure why reading has to be exclusive. |
On the one hand, the c.get.flatMap { v =>
/* here I don't have exclusive access, because the lock have been already released */
} So On the other hand, this:
This seems like the answer would be application-specific. I was trying to come up with some scenarios for using |
When you need to atomically update some state with the result of an effect that can/should not be run more than once. If you just need to atomically update state with the result of a pure function, use If you need to atomically update state with the result of an effect that is okay to run more than once, use |
Sure. I just had trouble coming up with a scenario when that happens (e.g., the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find @durban's argument to be pretty compelling here: get
locking isn't really helpful.
@armanbilge @djspiewak should we change I would think that is a bad idea, but still don't understand why that read should block whereas this read shouldn't. |
|
@armanbilge right, I know that, I was just still confused why that "read" is different from this "read".
|
At least, I don't see why it should. It seems to me that the primary concern is that
get
shouldn't see inconsistent state, otherwise it doesn't matter if someone happens to be modifying/updating the cell at that moment. Also there's no reason that concurrentget
s should have to take turns acquiring the mutex; they can all just read.cc @BalmungSan