非阻塞算法(Non-blocking Algorithm)
目录
在并发编程中,无锁意味着任何线程的失败、挂起,不能引起其他线程失败、挂起。在一些操作中,无锁算法提供了一个传统阻塞算法之外的,非常有效的选择。无锁算法主要有两种实现目标:Lock-Free(无锁)和Wait-Free(无等待)。
An algorithm is called non-blocking if failure or suspension of any thread cannot cause failure or suspension of another thread.
A non-blocking algorithm is lock-free if there is guaranteed system-wide progress, and wait-free if there is also guaranteed per-thread progress.
无锁算法(Lock-Free)
: 无锁系统中,虽然存在特殊的计算被阻塞一段时间,之外,所有的CPU都可以持续操作其他计算。当一个给定的线程被阻塞了,所有的CPU都可以持续做其他有效的没有资源的任务。无锁算法通过偶尔增加某些事务的延迟,增加了整体的吞吐量。大部分的高端数据库系统都采用了无锁算法。
无等待算法(Wait-Free)
: 相对地,无等待算法除了保证所有的CPU持续做有用的任务,同时保证没有操作可以被其他操作阻塞。无等待算法比无锁算法有更高的要求,确保了没有损失特殊事务延迟而达到高吞吐量。无等待算法是比较难实现、测试、debug的。Linux