并发 Haskell 仍然仅限于单个操作系统线程吗?
在 2005 年的一篇研究论文中说
并发 Haskell 目前仅针对单处理器实现。运行时在单个操作系统线程中调度轻量级 Haskell 线程。 Haskell 线程仅在明确定义的“安全点”处挂起;他们不能在任意时刻被先发制人。
这是否发生了变化,或者并发 Haskell 仍然仅限于单个操作系统线程?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
[编辑:问题只提到了 Concurrent Haskell,但我相信引用的论文是“Composable Memory Transactions”,该论文首次描述了 Haskell STM。如果我错了,请纠正我。]
STM 现在在多核上工作得很好。并行实现首先在 GHC 6.6 中发布,并使用细粒度的两阶段锁定策略;也就是说,要提交事务,实现首先尝试锁定事务中涉及的每个变量,然后提交更改,最后解锁所有变量。获取锁不会阻塞:如果锁已被持有,则事务将中止并重试(这可以避免在锁获取阻塞时出现的通常的锁顺序反转死锁)。
这种 STM 实现当然不是最快的 - 文献描述了许多可以带来更好性能的替代技术,但 GHC 的实现相对简单,并且不涉及任何全局锁(对不同变量集进行操作的事务可以并行进行而不会受到干扰) )。
[edit: the question only mentions Concurrent Haskell, but the paper referenced is, I believe, "Composable Memory Transactions", the paper in which Haskell STM was first described. Please correct me if I'm wrong here.]
STM works just fine on multiple cores now. The parallel implementation was first shipped in GHC 6.6, and uses a fine-grained two-phase locking strategy; that is, to commit a transaction the implementation first attempts to lock each variable involved in the transaction, then commits the changes, and finally unlocks all the variables. Acquiring a lock does not block: if the lock is already held, then the transaction aborts and retries (this avoids the usual lock-order-reversal deadlock that would apply if lock acquisition was blocking).
This STM implementation is certainly not the fastest - the literature describes many alternative techniques that would result in better performance, but GHC's implementation is relatively straightforward and doesn't involve any global locks (transactions operating on distinct sets of variables can proceed in parallel without interference).
自 2004 年以来,GHC 可以使用多核来实现并发和并行 Haskell。并发、并行、嵌套数据并行 Haskell 都使用相同的多线程运行时。
GHC can use multi-cores for Concurrent and Parallel Haskell since 2004. Concurrent, Parallel, Nested Data Parallel Haskell all use the same multi-threaded runtime.
GHC Haskell 在多核上运行良好
GHC Haskell 程序,自 2004 年以来,在多个操作系统线程上运行多个 Haskell 线程,这些线程分布在多个内核上。
此外,您还可以从以下位置获取多核 Haskell 的最新状态这个问题。
GHC Haskell runs well on multicores
GHC Haskell programs, since 2004, run multiple Haskell threads over multiple OS threads, which are distributed over multiple cores.
Also, you can get the latest status of multicore Haskell from this SO question.