2 ms·
Clojure generally uses CAS semantics, although it also has transactions that can update multiple refs atomically. So nothing is ever "silently overwritten" and
by reitzensteinm 7y ago
Clojure generally uses CAS semantics, although it also has transactions that can update multiple refs atomically. So nothing is ever "silently overwritten" and there's no locking required, it's all optimistic concurrency.
However, to agree with part of your point, an atom being updated with CAS can only ever progress linearly; if you bang 8 threads in a loop trying to update it, you might as well use a lock, because 7/8 of the work is going to be thrown out.
They should only be used for cases where on average one thread or less is working on updating it; anything more, and it needs to be split, the problem rethought, or some mechanism for not throwing out wasted work implemented.
It's not a silver bullet.