Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No modern language I know of beats Haskell’s support for STM:

https://wiki.haskell.org/Software_transactional_memory

As I always say, Haskell is the Mercedes of programming languages.



> Haskell is the Mercedes of programming languages.

Comfortable, packed with features, pretty fast given its weight, kind of elitist yet approachable if you invest time in it? :p


ding ding ding!

Also something about inventing/spurring mass adoption of airbags and ABS. Safe and fast.


I have a repo with six sample algorithms of increasing complexity: https://github.com/jasonincanada/stm-haskell


Common Lisp has it too, via https://stmx.org/ I believe it supports the Intel TSX stuff if present and falls back to a software implementation if not present.


I don't have much experience with Haskell, but Clojure also has STM out-of-the-box. I don't know if it's the approach described in paper, but it's quite fast. It's probably made faster by the fact that almost all data in Clojure is immutable.

"The Clojure STM uses multiversion concurrency control with adaptive history queues for snapshot isolation, and provides a distinct commute operation."

https://clojure.org/reference/refs, for the curious and brave


Interestingly, I’ve been using Clojure since 2009 and I’ve never once used STM (outside of playing around to learn how to use it). I’ve used agents on occasion, I’ve used atoms, I’ve used core.async a lot, but refs and STM, to me (ie YMMV) seem like one of those things that seemed like a useful great idea, that in practice just wasn’t really necessary.

Maybe others have had a different experience, of course. This is just an observation about my own code and the libraries I use.


No, your assessment is pretty accurate. I've only encountered refs once in the wild, and only because it was too much hassle to refactor working code to use an atom.

It turns out that updating a single storage point in an atom with a CAS serves 99.9% of use cases, and is much, much simpler than ref-based code.


> but refs and STM, to me (ie YMMV) seem like one of those things that seemed like a useful great idea, that in practice just wasn’t really necessary.

Haskellers (including myself) tend to default to STM to take advantage of atomicity.

Of course it's easy to make the safe choice when the shared interface between concurrency primitives make switching very low cost.

More: https://www.oreilly.com/library/view/parallel-and-concurrent...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: