Re:You Can Do Any Kind of Atomic Read-Modify-Write Operation
by atomic_cheese on Thursday October 08, 2015 @02:39PM
(#10355011)
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.
[ Parent
| on HN ]
Re:You Can Do Any Kind of Atomic Read-Modify-Write Operation
by dustyleary on Thursday October 08, 2015 @04:54PM
(#10356141)
Thanks, 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.