A Tour of OSAtomic
To see how you can use these, let’s consider how you would write
OSAtomicAdd32
using compare and swap. Again, it works using a transaction model. First, fetch the original value. Then add to obtain a new value. Finally, use compare and swap with the original and new values. If it failed, go back and try everything again.