I am trying to find the differences between what Clojure calls an STM and what is implemented in Haskell as STM. Taking the actual language semantic differences aside I am a little confused as Rich Hickey says in his speech that Clojure's implementation of STM is very different from anything else out there, but I don't understand the differences apart from the language choice.
Clojure STM has 3 big unique features:
- Implements MVCC snapshot avoiding transactions restarts on read invalidation.
- Ensures references on read-writes provides a kind of manual control over resource acquisition order.
- Has explicit commute which reduces retries on commutative writes.
For Haskell STM, see SPJ's papers: http://research.microsoft.com/en-us/um/people/simonpj/papers/stm/
Of particular use are "Composable memory transactions" and "Transactional memory with data invariants". GHC's implementation of STM indeed isn't MVCC. I don't recall all the implementation details, but my understanding is that the description in the papers isn't all that different from what currently exists in GHC.
(note that MVCC, in clojure or elsewhere, makes possible write-skew -- see, e.g., here: http://en.wikipedia.org/wiki/Snapshot_isolation)
orElse
combinator for atomically composing transactions. –
Mayenne STM
is a MonadPlus
, which allows you to specify additional failure conditions within the transaction context. i.e. if final account balance is negative, fail/retry the txn. It also allows you to share that logic with other MonadPlus
classes easily; the same function would show the result of all potential valid transactions given a List
of accounts and purchases. This can be useful if the logic is complex. I don't think either is possible in clojure. –
Cornish Mark Volkmann did a very detailed presentation on STMs in general (and Clojure's STM in particular) at Strange Loop 2009 which you can find here (article and slides here). I don't really know of any other resource (other than the code) for understanding how Clojure's STM works.
© 2022 - 2024 — McMap. All rights reserved.