Hacker News new | ask | show | jobs
by romero-jk 1657 days ago
This is how clojure does it: https://clojure.org/reference/atoms

It's very costly though.

1 comments

Is it particularly costly compared to locks?

Under the hood it's a effectively a single CAS instruction that loops on failure (which only occurs under contention, but then you have waiting with locks too).