programming languages - Why are closures suddenly useful for optimizing programs to run on multiple cores? -


I have read the claim that closing "war on multicore" (or "block") is a useful tool because

[...] They allow you to make units of work, each of which has a copy of their stack, and as a result, do not move on each other's toes. What's more, you can pass these units in a rough way as they are worth, when in actual fact they have a complete stack of values ​​(different intentions) and executable code to do some operations.

Now, I am not discussing the usefulness of general shutdown for concurrent programming in a shared memory memory and possibly , but what is the difference with a thread that only works on local data (or processes, or actor, or ...)?

Is useful for a uniformly concurrent programming without the scheduler?

What are the non-local side effects that stop it? The argument is that by completing your programming language, it is easy to do some work in the second thread.

I think the author has mentioned the importance of the high-order function in that argument.

My favorite introduction to high order tasks, I will not try to present a bad replica here.

By using the closures, you do not give parallels for free if you execute the closure for the loop, e.g.

 for  (int i = 0; i & lt; numElements; I ++) {result [i] = off (input [i], i); }  

Because language can not tell if the closed (A, B) changes in any way or other values ​​in the input array. But languages ​​with high-order functions like map specify that the values ​​passed in the map should not be seen or changed in other values, and it affects other results. Should stop. Therefore, the code like the following, which is common in functional languages, can be parallel to the need for you to create a pool of no-worker threads and close them:

  Result = Map (closing, input, [0..name elements-1]);  

In these languages, take away the pain of declaring a new function somewhere for a small piece of closing code. It's more fun to use the high-order function.

The following Haskell code defines the function f , which takes a list of numbers and returns a list where each input i to 2i + 1 . By comparing the problem of 2i + 1 to create a function, it is 1 row of code instead of 2.

  f nums = map (\ i -> 2; i + 1) nums  

Again, see such strong arguments that the real This is how the scales are up to the code base.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -