9 ms·
I'm pretty sure that example is actually fine - if there's a concurrent writer, the modified value will be loaded into oldValue. Repeating shared.load is unnece
by atomic_cheese 11y ago
I'm pretty sure that example is actually fine - if there's a concurrent writer, the modified value will be loaded into oldValue. Repeating shared.load is unnecessary since that operation occurs as part of compare_exchange_weak.
- dustyleary 11y agoThanks, my mistake. I've been bit by this before. I sometimes wish you had to mark "reference-of" just like you have to mark "address-of" with &. It's obvious that blah(&foo) might modify foo, without needing to examine the signature of blah(). The tradeoff is a bit of code clutter when you add a symbol (something like shared.compare_exchange_weak(%oldValue, oldValue * multiplier)), and a violation of DRY, since the information provided by this symbol would be redundant.