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

If you're using an atom, you're already sticking state in a place; the problem with atoms is choosing granularity. If one atom has everything in it, it will become a point of contention.

If your compare-and-set returns false, what do you do?

STM resolves these issues by letting you coordinate updates to more granular, finer-scoped refs



The drawback here is that the STM (at least the Clojure implementation few years ago when I tested it) is orders of magnitude slower than simple atomic reference.

It actually does not have to be, but this is how it is (was) implemented. I built a simple STM (in Java) as part of my bachelor thesis and its performance was comparable to the atomic reference.


If all you need is a simple atomic reference, then great.

I'm not convinced a single atomic reference sufficiently covers enough use cases, however.


Yes, it probably does not, and I think that using STM is actually fine in Clojure. Just you have to pay attention to the limitations.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: