2 ms·
I vaguely recall that LL/SC solves the ABA problem whereas load-modify-store does not. It's been a while, so I'm going to define my understanding of the ABA pr
by phamilton 5y ago
I vaguely recall that LL/SC solves the ABA problem whereas load-modify-store does not.
It's been a while, so I'm going to define my understanding of the ABA problem in case I misunderstood it:
x86 only supplies cmpxchange instructions on which will update a value only if it matches the passed in previous value. There's a class of concurrency bugs where the value is modified away from it's initial value and then modified again back to it's value. cmpxchange can't detect that condition, so if it's a meaningful difference often the 128-bit cmpxchange will be used with a counter in the second 64-bits that is incremented on each write to catch this case.
LL/SC will trigger on any write, rather than comparing the value, providing the stronger guarantee.
(Please correct me if this is inaccurate, it's been a hit minute since I learned this and I'd love to be more current on it).
- zozbot234 5y agoAIUI, a cmpxchg loop is enough to implement read-modify-write of any atomically sized value. The ABA problem becomes relevant when trying to implement more complex lock-free data structures.