Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell vs. Python threading model

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 these threads? Thanks for all the info: documentation/insights greatly appreciated.

like image 413
Dervin Thunk Avatar asked Jul 05 '11 18:07

Dervin Thunk


2 Answers

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.

like image 56
fuz Avatar answered Sep 23 '22 06:09

fuz


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.

like image 21
Eli Bendersky Avatar answered Sep 23 '22 06:09

Eli Bendersky