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

后端 未结 3 1944
情歌与酒
情歌与酒 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:20

    From the weaker to the stronger condition:

    A method is lock-free if it guarantees that infinitely often some method call finishes in a finite number of steps.

    A method is wait-free if it guarantees that every call finishes its execution in a finite number of steps.

    Clearly, any wait-free method implementation is also lock-free, but not vice versa. Lock-free algorithms admit the possibility that some threads could starve.

    However, from a "Practical Perspective" there are many situations in which starvation, while possible, is extremely unlikely, so a fast lock-free algorithm may be more attractive than a slower wait-free algorithm.

    NOTE: An even stronger property it is called "bounded wait-free" which means: there is a bound on the number of steps a method call can take.

提交回复
热议问题