What's the difference between lockless and lockfree?

前端 未结 2 648
不知归路
不知归路 2021-01-04 21:01

In some articles about algorithm, some use the word lockfree, and some use lockless. What\'s the difference between lockless and

2条回答
  •  生来不讨喜
    2021-01-04 21:10

    Lock-free is a more formal thing (look for lock-free algorithms). The essence of it for data structures is that if two threads/processes access the data structure and one of them dies, the other one is still guaranteed to complete the operation.

    Lockless is about implementation - it means the algorithm does not use locks (or using the more formal name - mutual exclusion).

    Therefore a lock-free algorithm is also lockless (because if one thread locks and then dies the other one would wait forever) but not the other way around - there are algorithms which don't use locks (e.g. they use compare-and-swap) but still can hang if the other process dies. The dpdk ring buffer mentioned above is an example of lockless which is not lock-free.

提交回复
热议问题