Sent from my iPhone
On Oct 16, 2012, at 10:39 AM, Jason Greene <jason.greene(a)redhat.com> wrote:
Yes if you get the ordering right, it can certainly be done. You
might have to introduce a state-based CAS or secondary lock though for some scenarios (I
haven't thought through them all) I think Manik's point though was just that
getting it right is harder than just making the whole thing atomic.
So actually spending more than a few seconds of thought, just adding a lock to the chm
before acquiring it is sufficient and efficient. Really the only loss compared to
computeIfAbsent is the cost of lock object instantiation. If you use computeIfAbsent you
might want to add a fast path initial acquire (volatile write vs the typical state CAS) to
the ownablelock (if not already there)