[concurrency-interest] Immutable object conundrums

Jim Andreou jim.andreou at gmail.com
Tue Jun 30 08:21:49 EDT 2009

This is a big one, I'll answer only in the question in the middle.

2009/6/30 Ashley Williams <ashpublic at mac.com>:
> Then I have to update the parent aggregate with the return value from
> MyChild.modify(). But if ThreadA and ThreadB
> both try to do this then I have to consider the possibility that one of the
> updates will be overwritten by the other. So
> rather than immutable objects being a silver bullet, I now appear to be
> firmly in the territory of lost-updates,
> unrepeatable reads and other isolation problems. Is this an inevitability,
> or is there some other way people out there
> are designing their way round this?

You need to atomically update the root reference to this structure
(via cas). If a thread loses the race, it retries. This is a general
technique that can transform any sequential structure to a lock-free
one (described by Herlihy somewhere I think), but notice it can create
lots of contention if updates are often and/or copying is slow, i.e.
it doesn't really scale very well (as can be expected by a so
generallly applicable technique).


More information about the Concurrency-interest mailing list