Examples/Illustration of Wait-free And Lock-free Algorithms

后端 未结 3 1946
情歌与酒
情歌与酒 2021-01-31 10:01

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

3条回答
  •  梦毁少年i
    2021-01-31 10:21

    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.

提交回复
热议问题