-
Notifications
You must be signed in to change notification settings - Fork 418
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
Add a simple STM #19
Comments
In a very early version of this gem I implemented an |
We can implement the API right now, just by using a global lock for all |
I've created a |
I have opted to make numerics succeed in CAS if they are == as far as Ruby is concerned. This makes numeric CAS have a bit more overhead, since we do (at least) two additional instanceof and an additional == call, as well as looping until there's no contention for reference equality, but it fits the spirit of what people want better than strict reference equality. See #19.
Software transactional memory provides a simple model for updating multiple references with atomicity, isolation and consistency. Completely transparent STM in Ruby would require language modifications, but if we have a transactional variable object, we can do it quite easily. This is what Haskell did, with their TVar. Clojure's implementation is similar I believe.
The action inside the
atomically
intransfer
either completes or it does not - there's no chance of money being taken from the first account but not appearing in the second, and no chance of someone being able to observe the state where it's been taken from the first and not appeared in the second yet.This transactional variable approach has a drawback in that we can't provide strong isolation - only weak isolation - that means that if you access the variables outside of an
atomically
it doesn't work. But don't do that then.Thoughts?
The text was updated successfully, but these errors were encountered: