Re:Rich Hickey: STMs vs Locks [2008]
by technomancy on Wednesday November 30, 2011 @12:53PM
(#3295951)
> I think if I were just doing a single pointer swap, I'd
> probably build my own mini-transaction out of a loop and
> atomic variable to hold (and swap) the pointer.
FWIW, this was implemented in Clojure soon after this conversation; see atoms.
But, I still agree with you because even then, I would try to keep the amount of data which needs to be atomically shared to a minimum, so the problems discussed would be minimal.
Also, as you mentioned, with immutable data, even STM touching multiple complex data structures is simplified because you can create the new versions independently and then simply swap a pointer or two, so in funtional languages with immutable data, I expect STM to be turned into a few atomic pointer swaps under the hood.