I\'ve read that wait-free causes all threads to finish independently and lock-free ensures the program as a whole completes. I couldn\'t quite get it. Can anyone give an example
No, Lock-free
means a program without locks. Although, a wait-free
algorithm is also lock-free
; however, vice versa doesn't hold. But, both are non-blocking algorithms, nonetheless.
This wiki entry is a great read to understand lock-free and wait-free mechanism.
Well, java.util.concurrent.atomic package is an example of lock-free
programming on single variables. And in Java 7 ConcurrentLinkedQueue is an example of wait-free
implementation.
For further insight, I would like you to read this article, Going atomic by Brian Goetz -- the guy who wrote Java Concurrency in Practice.