Atomically increment two integers with CAS
问题 Apparently, it is possible to atomically increment two integers with compare-and-swap instructions. This talk claims that such an algorithm exists but it does not detail what it looks like. How can this be done? (Note, that the obvious solution of incrementing the integers one after the other is not atomic. Also, stuffing multiple integers into one machine word does not count because it would restrict the possible range.) 回答1: Make me think of a sequence lock. Not very accurate (putting this