Python, Ruby, Haskell - Do they provide true multithreading?

后端 未结 8 644
我寻月下人不归
我寻月下人不归 2021-02-01 22:31

We are planning to write a highly concurrent application in any of the Very-High Level programming languages.

1) Do Python, Ruby, or Haskell support true multithreading?

相关标签:
8条回答
  • 2021-02-01 22:48

    I second the choice of Erlang. Erlang can support distributed highly concurrent programming out of the box. Does not matter whether you callit "multi-threading" or "multi-processing". Two important elements to consider are the level of concurrency and the fact that Erlang processes do not share state.

    No shared state among processes is a good thing.

    0 讨论(0)
  • 2021-02-01 22:49

    The GHC compiler will run your program on multiple OS threads (and thus multiple cores) if you compile with the -threaded option and then pass +RTS -N<x> -RTS at runtime, where <x> = the number of OS threads you want.

    0 讨论(0)
  • 2021-02-01 22:51

    Haskell is thread-capable, in addition you get pure functional language - no side effects

    0 讨论(0)
  • 2021-02-01 22:52

    The current version of Ruby 1.9(YARV- C based version) has native threads but has the problem of GIL. As I know Python also has the problem of GIL.

    However both Jython and JRuby(mature Java implementations of both Ruby and Python) provide native multithreading, no green threads and no GIL.

    Don't know about Haskell.

    0 讨论(0)
  • 2021-02-01 22:57

    The Haskell implementation, GHC, supports multiple mechanisms for parallel execution on shared memory multicore. These mechanisms are described in "Runtime Support for Multicore Haskell".

    Concretely, the Haskell runtime divides work be N OS threads, distributed over the available compute cores. These N OS threads in turn run M lightweight Haskell threads (sometimes millions of them). In turn, each Haskell thread can take work for a spark queue (there may be billions of sparks). Like so: enter image description here

    The runtime schedules work to be executed on separate cores, migrates work, and load balances. The garbage collector is also a parallel one, using each core to collect part of the heap.

    Unlike Python or Ruby, there's no global interpreter lock, so for that, and other reasons, GHC is particularly good on mulitcore in comparison, e.g. Haskell v Python on the multicore shootout

    0 讨论(0)
  • 2021-02-01 22:58

    For real concurrency, you probably want to try Erlang.

    0 讨论(0)
提交回复
热议问题