开发者

Haskell vs. Python threading model

开发者 https://www.devze.com 2023-03-17 05:54 出处:网络
Maybe there\'s someone out there with the right interests that will know how to answer this. Basically the question is: What are the differences between the multiprocessing module in Python, and the p

Maybe there's someone out there with the right interests that will know how to answer this. Basically the 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 开发者_Python百科these threads? Thanks for all the info: documentation/insights greatly appreciated.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消