Haskell 与 Python 线程模型

发布于 2024-11-18 17:23:07 字数 127 浏览 2 评论 0原文

我的问题是:Python 中的多处理模块和 Haskell 中的并行性之间有什么区别。例如:Python 创建的线程是否映射到操作系统线程?

如果是这样,如果线程多于核心怎么办?它们是否复用到操作系统线程中?谁来调度这些线程?

My question is: what are the differences between the multiprocessing module in Python, and the parallelism in Haskell. For instance: are threads created in Python mapped to OS threads?

If so, what if there are more threads than cores? Are they multiplexed into the OS threads? Who schedules these threads?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼前雾蒙蒙 2024-11-25 17:23:07

与 Python 不同(参见 Eli 的回答),哈斯克尔则完全不同。并发(多个线程处理程序的不同方面)和并行(多个线程只是为了加速计算)之间存在差异。两者均由 Haskell RTS 管理的轻量级线程处理。在第二种情况下,可以使用诸如 pseqpar 之类的原语来提示运行时在另一个线程中进行计算(如果这有优势的话)。运行时会自动决定这一点。

As opposed to Python (See Eli's answer), the threading model of Haskell is quite different. You have a difference between concurrency (multiple threads handling different aspects of the program) and parallelism (multiple threads just to speed up computation). Both are handled by lightweight threads managed by the Haskell RTS. In the second case, one can use primitives like pseq and par that hints the runtime to do the calculation in another thread, if this gives an advantage. The runtime automagically decides this.

说好的呢 2024-11-25 17:23:07

Python multiprocessing 模块与线程无关。它试图提供一个类似于threading(它确实公开线程)的API,并在下面有进程。

Python 线程映射到操作系统线程,如果您创建的线程多于内核,则会发生与在 C 中执行完全相同的事情(pthreads、Win API 线程等) - 操作系统处理核心之间的线程。

网上有很多关于Python线程的信息,Google一下就可以了。

The Python multiprocessing module has nothing to do with threads. It tries to provide an API similar to threading (which does expose threads) with processes underneath.

Python threads are mapped to OS threads, and if you create more threads than cores the exact same thing happens as if you'd do it in C (pthreads, Win API threads, etc.) - the OS juggles the threads between cores.

There's a lot of information online about Python threads, just Google it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文