The OCaml GC imposes a global lock that prevents mutators (threads) from running in parallel although they can run concurrently (interleaved). I believe the same is true of SML/NJ and MLton but not PolyML, GHC, F#, Clojure and Scala.
OCaml GC强制执行全局锁定,以防止mutators(线程)并行运行,尽管它们可以并发运行(交错)。我相信SML / NJ和MLton也是如此,但不是PolyML,GHC,F#,Clojure和Scala。
What other functional language implementations allow threads to run in parallel?
还有哪些其他功能语言实现允许线程并行运行?
8 个解决方案
#1
I'm happy to tell you that you're right and that F#, being based on the CLR, doesn't suffer from that limitation at all, and instead benefits from multithreading specific features including async workflows, the mailboxprocessor, and the wonderful upcoming (.NET 4.0) Task Parallel Library.
我很高兴地告诉你,你是对的,基于CLR的F#完全没有受到这种限制,而是受益于多线程特定功能,包括异步工作流,邮箱处理器和即将推出的即将发布的功能(.NET 4.0)任务并行库。
#2
There are a number of good implementations out there. At the moment, the Haskell people seem to be getting the best results (see ICFP 2009 paper by Simon Marlow and others as well as Haskell Symposium 2009 paper by Donnie Jones and others). Erlang is quite close behind, especially if you want to go distributed.
那里有很多很好的实现。目前,Haskell人似乎获得了最好的结果(参见Simon Marlow和其他人的ICFP 2009论文以及Donnie Jones和其他人的Haskell Symposium 2009论文)。 Erlang非常落后,特别是如果你想分发。
In six to twelve months the answers may have changed :-)
在六到十二个月内,答案可能已经改变:-)
#4
Scala and Clojure are both running on the JVM, which allows real concurrency without any single point of contention bottlenecks.
Scala和Clojure都在JVM上运行,它允许真正的并发,没有任何单点争用瓶颈。
#5
Erlang implements its own processes and process schedule and allows thousands, tens of thousands and even millions of Erlang processes (inside a single Operating System process).
Erlang实现了自己的流程和流程计划,并允许数千,数万甚至数百万个Erlang流程(在单个操作系统流程中)。
In SMP and multi-core machines the Erlang Virtual Machine will allocate as many OS threads and OS processes to its process scheduler and process queue to maximise its use of underlying concurrent operations in the hardware architecture.
在SMP和多核机器中,Erlang虚拟机将为其进程调度程序和进程队列分配尽可能多的操作系统线程和操作系统进程,以最大限度地利用硬件体系结构中的底层并发操作。
The concurrency paradigm exposed to the applications remains the same, of course.
当然,暴露于应用程序的并发范例仍然是相同的。
#6
In addition to Haskell, you can run processes concurrently in Erlang (Concurrency-Oriented Programming) and you can also do so in F# using .NET Parallel Extensions and Asynchronous Workflows.
除了Haskell之外,您还可以在Erlang(面向并发的编程)中同时运行进程,也可以使用.NET Parallel Extensions和Asynchronous Workflow在F#中执行。
#7
Just some additions to confirm further parts of the speculative list:
只需添加一些内容即可确认推测列表的其他部分:
-
Poly/ML supports native threads (POSIX threads or Windows threads) since version 5.2 (from 2006). Current Poly/ML 5.5 (summer 2012) has improved support for parallel memory management: some of the GC phases use multiple threads, there is special support for online sharing of immutable values to reduce memory footprint of huge applications.
Poly / ML支持自5.2版本(2006年起)的本机线程(POSIX线程或Windows线程)。当前Poly / ML 5.5(2012年夏季)改进了对并行内存管理的支持:一些GC阶段使用多个线程,特别支持在线共享不可变值以减少大型应用程序的内存占用。
-
Isabelle/ML provides an add-on future library for Poly/ML threads. Isabelle is an interactive theorem prover, but it is integrated with an augmented version SML based on Poly/ML.
Isabelle / ML为Poly / ML线程提供了一个附加的未来库。 Isabelle是一个交互式定理证明器,但它与基于Poly / ML的增强版SML集成。
#8
python is not a particularly functional language, and with the GIL, it's not very parallel, either, but combined with the multiprocessing module (standard since 2.6), you get both, but it's not quite as elegant as pure functional languages.
python不是一种特别功能的语言,并且使用GIL,它也不是很平行,但是与多处理模块(2.6以后的标准)相结合,你得到了两者,但它并不像纯函数语言那么优雅。
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
pool = Pool(processes=4) # start 4 worker processes
result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously
print result.get(timeout=1) # prints "100" unless your computer is *very* slow
print pool.map(f, range(10)) # prints "[0, 1, 4,..., 81]"
#1
I'm happy to tell you that you're right and that F#, being based on the CLR, doesn't suffer from that limitation at all, and instead benefits from multithreading specific features including async workflows, the mailboxprocessor, and the wonderful upcoming (.NET 4.0) Task Parallel Library.
我很高兴地告诉你,你是对的,基于CLR的F#完全没有受到这种限制,而是受益于多线程特定功能,包括异步工作流,邮箱处理器和即将推出的即将发布的功能(.NET 4.0)任务并行库。
#2
There are a number of good implementations out there. At the moment, the Haskell people seem to be getting the best results (see ICFP 2009 paper by Simon Marlow and others as well as Haskell Symposium 2009 paper by Donnie Jones and others). Erlang is quite close behind, especially if you want to go distributed.
那里有很多很好的实现。目前,Haskell人似乎获得了最好的结果(参见Simon Marlow和其他人的ICFP 2009论文以及Donnie Jones和其他人的Haskell Symposium 2009论文)。 Erlang非常落后,特别是如果你想分发。
In six to twelve months the answers may have changed :-)
在六到十二个月内,答案可能已经改变:-)
#3
Haskell supports parallel threads via Data Parallel Haskell
Haskell通过Data Parallel Haskell支持并行线程
#4
Scala and Clojure are both running on the JVM, which allows real concurrency without any single point of contention bottlenecks.
Scala和Clojure都在JVM上运行,它允许真正的并发,没有任何单点争用瓶颈。
#5
Erlang implements its own processes and process schedule and allows thousands, tens of thousands and even millions of Erlang processes (inside a single Operating System process).
Erlang实现了自己的流程和流程计划,并允许数千,数万甚至数百万个Erlang流程(在单个操作系统流程中)。
In SMP and multi-core machines the Erlang Virtual Machine will allocate as many OS threads and OS processes to its process scheduler and process queue to maximise its use of underlying concurrent operations in the hardware architecture.
在SMP和多核机器中,Erlang虚拟机将为其进程调度程序和进程队列分配尽可能多的操作系统线程和操作系统进程,以最大限度地利用硬件体系结构中的底层并发操作。
The concurrency paradigm exposed to the applications remains the same, of course.
当然,暴露于应用程序的并发范例仍然是相同的。
#6
In addition to Haskell, you can run processes concurrently in Erlang (Concurrency-Oriented Programming) and you can also do so in F# using .NET Parallel Extensions and Asynchronous Workflows.
除了Haskell之外,您还可以在Erlang(面向并发的编程)中同时运行进程,也可以使用.NET Parallel Extensions和Asynchronous Workflow在F#中执行。
#7
Just some additions to confirm further parts of the speculative list:
只需添加一些内容即可确认推测列表的其他部分:
-
Poly/ML supports native threads (POSIX threads or Windows threads) since version 5.2 (from 2006). Current Poly/ML 5.5 (summer 2012) has improved support for parallel memory management: some of the GC phases use multiple threads, there is special support for online sharing of immutable values to reduce memory footprint of huge applications.
Poly / ML支持自5.2版本(2006年起)的本机线程(POSIX线程或Windows线程)。当前Poly / ML 5.5(2012年夏季)改进了对并行内存管理的支持:一些GC阶段使用多个线程,特别支持在线共享不可变值以减少大型应用程序的内存占用。
-
Isabelle/ML provides an add-on future library for Poly/ML threads. Isabelle is an interactive theorem prover, but it is integrated with an augmented version SML based on Poly/ML.
Isabelle / ML为Poly / ML线程提供了一个附加的未来库。 Isabelle是一个交互式定理证明器,但它与基于Poly / ML的增强版SML集成。
#8
python is not a particularly functional language, and with the GIL, it's not very parallel, either, but combined with the multiprocessing module (standard since 2.6), you get both, but it's not quite as elegant as pure functional languages.
python不是一种特别功能的语言,并且使用GIL,它也不是很平行,但是与多处理模块(2.6以后的标准)相结合,你得到了两者,但它并不像纯函数语言那么优雅。
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
pool = Pool(processes=4) # start 4 worker processes
result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously
print result.get(timeout=1) # prints "100" unless your computer is *very* slow
print pool.map(f, range(10)) # prints "[0, 1, 4,..., 81]"