| I don't like usage of the term "lock free" to mean "locks that are less costly". There's a difference between (A) locking (waiting, really) on access to a critical section (where you spinlock, yield your thread, etc.) and (B) locking the processor to safely execute a synchronization primitive (mutexes/semaphores). CAS is "lock free" only in the sense that it doesn't require the processor to stop the world in order to flip the mutex boolean. It's still a mutex, and it still gates access to a critical section, and you still need some kind of strategy to deal with waiting for the critical section to become available (e.g., spinlocking, signaling the OS to sleep thread execution). An example of operation using coarse locks would be a method in Java with “synchronized” keyword.
If a thread T is executing a synchronized method on a particular object,
no other concurrent thread can invoke any other synchronized method on the same object.
That's just putting one giant mutex around all access to the object. Having finer granularity != "lockless". |
No, CAS is lock free in the sense that a process or thread that freezes for whatever reason while doing a CAS operation cannot cause the entire system to stop making progress (provided your hardware is working as intended).
That's the only thing that matters to say if something is 'lock free' or not, and CAS meets that definition.
If you want some other property that's fine, but that's not what anyone understands by 'lock free'.