Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are functional languages considered a boon for multi threaded environments?

I hear a lot about functional languages, and how they scale well because there is no state around a function; and therefore that function can be massively parallelized.

However, this makes little sense to me because almost all real-world practical programs need/have state to take care of. I also find it interesting that most major scaling libraries, i.e. MapReduce, are typically written in imperative languages like C or C++.

I'd like to hear from the functional camp where this hype I'm hearing is coming from..

like image 932
Billy ONeal Avatar asked May 25 '10 23:05

Billy ONeal


People also ask

What is the key advantage of using a multi threaded environment over a single-threaded environment?

At no time can a single-threaded application execute on more than one processor in the system. Multithreading applications can help the operating system distribute the processor time more evenly among the different tasks it needs to complete. As a result, all tasks move quickly toward resolution.

Why multithreaded environment is advantageous?

On a multiprocessor system, multiple threads can concurrently run on multiple CPUs. Therefore, multithreaded programs can run much faster than on a uniprocessor system. They can also be faster than a program using multiple processes, because threads require fewer resources and generate less overhead.


1 Answers

It's important to add one word: "there's no shared state".

Any meaningful program (in any language) changes the state of the world. But (some) functional languages make it impossible to access the same resource from multiple threads simultaneously. The absence of shared state makes multithreading safe.

like image 109
Igor Krivokon Avatar answered Oct 04 '22 04:10

Igor Krivokon