无等待和无锁算法的示例/说明

编程入门 行业动态 更新时间:2024-10-21 16:16:13
本文介绍了无等待和无锁算法的示例/说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我读到,免等待会导致所有线程独立完成,而免锁则确保了程序整体完成。我不太明白。谁能举一个例子(java)来说明这一点。

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 (java) illustrating this.

编辑:无锁意味着程序没有死锁吗?

Does lock-free mean a program without deadlock?

推荐答案

如果程序是无锁的,则基本上意味着它的至少一个线程可以保证在任意时间段内取得进展。如果某个程序死锁,则它的所有线程(以及整个程序)都无法取得进展-我们可以说它不是无锁的。由于无锁程序可以保证取得进展,因此可以保证它们完成(假定无例外地有限执行)。

If a program is lock-free, it basically means that at least one of its threads is guaranteed to make progress over an arbitrary period of time. If a program deadlocks, none of its threads (and therefore the program as a whole) cannot make progress - we can say it's not lock-free. Since lock-free programs are guaranteed to make progress, they are guaranteed to complete (assuming finite execution without exceptions).

无等待是一个更强的条件,这意味着每个线程都可以在任意时间段内取得进展,而与线程执行的时间/顺序无关;因此我们可以说线程独立完成。所有无需等待的程序都是无锁的。

Wait-free is a stronger condition which means that every thread is guaranteed to make progress over an arbitrary period of time, regardless of the timing/ordering of thread execution; and so we can say that the threads finish independently. All wait-free programs are lock-free.

我不知道有任何Java例子可以说明这一点,但我可以告诉您无锁/等待-免费程序通常使用CAS指令之类的低级原语实现而没有锁。

I don't know offhand of any Java examples which illustrate this but I can tell you that lock-free/wait-free programs are typically implemented without locks, using low-level primitives such as CAS instructions.

更多推荐

无等待和无锁算法的示例/说明

本文发布于:2023-11-30 20:00:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!