3 ms·
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 b
by platz 11y ago
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
- eveningcoffee 11y agoThe 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.
- platz 11y agoIf all you need is a simple atomic reference, then great. I'm not convinced a single atomic reference sufficiently covers enough use cases, however.
- eveningcoffee 11y agoYes, it probably does not, and I think that using STM is actually fine in Clojure. Just you have to pay attention to the limitations.