Functional programming and multicore architecture

前端 未结 9 1332
傲寒
傲寒 2020-12-08 08:36

I\'ve read somewhere that functional programming is suitable to take advantage of multi-core trend in computing. I didn\'t really get the idea. Is it related to the lambda c

9条回答
  •  时光取名叫无心
    2020-12-08 09:02

    The basic argument is that it is difficult to automatically parallelize languages like C/C++/etc because functions can set global variables. Consider two function calls:

    a = foo(b, c);
    d = bar(e, f);
    

    Though foo and bar have no arguments in common and one does not depend on the return code of the other, they nonetheless might have dependencies because foo might set a global variable (or other side effect) which bar depends upon.

    Functional languages guarantee that foo and bar are independant: there are no globals, and no side effects. Therefore foo and bar could be safely run on different cores, automatically, without programmer intervention.

提交回复
热议问题