At a first glance this may appear like a cool locking free operation that makes possible to perform a lot of higher level atomic operations without locking. Unfortunately if you study a bit more in depth the semantic it turns out that CAS is a weak, ill conceived, form of locking. Basically when CAS returns that it was not able to perform the operation because some client updated the key in the meantime you need to redo the operation again: this is like waiting for a lock, but with two main drawbacks:
- You will find that the lock was not obtained after you already did all the work to create the new value, issued and transfered the new value, and so on…
- There is no serialization of all the clients waiting for a key. […]
So IMHO CAS appears to be cool but it sucks.